FSharp.Core: Add Async.RunImmediate(Async<'T>, CancellationToken) - #14532
vzarytovskii wants to merge 3 commits into
Conversation
|
You can also (or I can do it in a follow-up PR) replace:
EDIT: |
We can't reuse it everywhere just yet, since |
| static member RunImmediate(computation: Async<'T>, ?cancellationToken: CancellationToken) = | ||
| let cancellationToken = defaultArg cancellationToken Async.DefaultCancellationToken | ||
| AsyncPrimitives.RunImmediate cancellationToken computation | ||
|
|
There was a problem hiding this comment.
Using ResultCell version here instead of TCS
T-Gro
left a comment
There was a problem hiding this comment.
Would be good to see tests showing the exception stack traces between RunImmediate and RumSynchronously.
Not sure I understand exactly what do you mean? Just to compare frames? Let me see if we already have such tests for existing run methods. There were no changes in how things are scheduled/executed. |
|
|
||
| computation.Invoke newCtxt) | ||
|
|
||
| static member RunImmediate(computation: Async<'T>, ?cancellationToken: CancellationToken) = |
There was a problem hiding this comment.
Probably should be preview right?
fsharp/src/FSharp.Core/prim-types.fsi
Line 2571 in bc88b51
| [<CompiledName("FSharpAsync")>] | ||
| type Async = | ||
|
|
||
| /// <summary>Runs the asynchronous computation and await its result.</summary> |
There was a problem hiding this comment.
| /// <summary>Runs the asynchronous computation and await its result.</summary> | |
| /// <summary>Runs the asynchronous computation and awaits its result.</summary> |
| let actual = $"{t}, after task: {d}" | ||
|
|
||
| if not (actual = $"Before: {d}, in async: {d}, after async: {d}, after task: {d}") then | ||
| failwith actual |
There was a problem hiding this comment.
Took me a while to understand what's going on here, I'd just give vars clear names ("threadIdBefore", "threadIdAfter"...) and assert them all against Thread.CurrentThread.ManagedThreadId.
|
I'd also suggest either here or in a followup to go through the codebase and make use of the new method. |
See fsharp/fslang-suggestions#1042
Do we need more tests around cancellation/exception handling?
Whitespace cleanup was intentional