Skip to content

Commit fe72289

Browse files
committed
Avoid Async.RunSynchronously
1 parent 4d314ee commit fe72289

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/Hedgehog.Stateful/Sequential.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,4 @@ module Sequential =
390390
return (combinedJournal, Failure)
391391
}
392392

393-
// Create property from async computation that returns (Journal, Outcome)
394-
// The lazy ensures execution only happens when forced (during followPath in recheck)
395-
Gen.constant (lazy (Async.RunSynchronously executionAsync))
396-
|> Property.ofGen
393+
Property.ofAsyncWithJournal executionAsync

src/Hedgehog/Property.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ module Property =
118118
/// The property succeeds when the async computation completes successfully, and fails if it throws an exception.
119119
/// This enables testing of asynchronous F# code.
120120
let ofAsync (asyncComputation : Async<'T>) : Property<'T> =
121-
Gen.constant (lazy (PropertyResult.ofAsyncWith asyncComputation))
121+
Gen.constant (lazy (PropertyResult.ofAsync asyncComputation))
122+
|> Property
123+
124+
/// Create Property from an async computation that produces a journal and outcome
125+
let ofAsyncWithJournal (asyncComputation : Async<Journal * Outcome<'T>>) : Property<'T> =
126+
Gen.constant (lazy (PropertyResult.ofAsyncWithJournal asyncComputation))
122127
|> Property
123128

124129
/// Discards test cases where the predicate returns false, causing Hedgehog to generate a new test case.

src/Hedgehog/PropertyResult.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ module internal PropertyResult =
1414
PropertyResult.Sync (journal, outcome)
1515

1616
/// Create an async PropertyResult from an async computation that produces a journal and outcome
17-
let ofAsync (asyncResult : Async<Journal * Outcome<'a>>) : PropertyResult<'a> =
17+
let ofAsyncWithJournal (asyncResult : Async<Journal * Outcome<'a>>) : PropertyResult<'a> =
1818
PropertyResult.Async asyncResult
1919

2020
/// Create an async PropertyResult by capturing exceptions from an async computation
21-
let ofAsyncWith (asyncComputation : Async<'a>) : PropertyResult<'a> =
21+
let ofAsync (asyncComputation : Async<'a>) : PropertyResult<'a> =
2222
PropertyResult.Async (async {
2323
try
2424
let! result = asyncComputation

0 commit comments

Comments
 (0)