-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FSharp.Core: Add Async.RunImmediate(Async<'T>, CancellationToken) #14532
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using ResultCell
version here instead of TCS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -1501,6 +1501,10 @@ type Async = | |||
|
|||
computation.Invoke newCtxt) | |||
|
|||
static member RunImmediate(computation: Async<'T>, ?cancellationToken: CancellationToken) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be preview right?
fsharp/src/FSharp.Core/prim-types.fsi
Line 2571 in bc88b51
[<Experimental("Experimental library feature, requires '--langversion:preview'")>] |
@@ -47,6 +47,42 @@ namespace Microsoft.FSharp.Control | |||
[<CompiledName("FSharpAsync")>] | |||
type Async = | |||
|
|||
/// <summary>Runs the asynchronous computation and await its result.</summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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