feat(Async): StartTaskImmediate - #20258
Conversation
# Conflicts: # tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
There was a problem hiding this comment.
Pull request overview
This PR introduces Async.StartTaskImmediate, a new FSharp.Core API that runs a task factory with the ambient Async.CancellationToken and then awaits the produced task/task-like value using Async.Await (non-AggregateException wrapping) semantics. It also updates documentation and unit tests to cover the new behavior and updates the public-surface baselines and release notes accordingly.
Changes:
- Add
Async.StartTaskImmediateoverloads forTask,Task<'T>,ValueTask,ValueTask<'T>, plus an SRTP-based overload for task-like.GetAwaiter()values. - Update
Await/AwaitTaskxmldoc to point users toStartTaskImmediatefor the “start + await with cancellation” scenario. - Add/extend unit tests and update surface area baselines + release notes.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs | Adds coverage for StartTaskImmediate across Task/ValueTask and task-like awaitables. |
| tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl | Updates netstandard2.1 release surface area baseline for the new APIs. |
| tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.debug.bsl | Updates netstandard2.1 debug surface area baseline for the new APIs. |
| tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.release.bsl | Updates netstandard2.0 release surface area baseline for the new Task-only APIs. |
| tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.debug.bsl | Updates netstandard2.0 debug surface area baseline for the new Task-only APIs. |
| src/FSharp.Core/async.fsi | Adds public API declarations and xmldoc for StartTaskImmediate, plus cross-references from Await/AwaitTask. |
| src/FSharp.Core/async.fs | Implements StartTaskImmediate in terms of binding Async.CancellationToken and awaiting via Async.Await. |
| docs/release-notes/.FSharp.Core/11.0.100.md | Adds a release note entry for Async.StartTaskImmediate. |
Suppressed comments (1)
tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs:906
- This new test module should also be part of NotThreadSafeResourceCollection, otherwise it may run in parallel with tests that mutate the global default cancellation token (Async.CancelDefaultToken), causing nondeterministic failures.
module AsyncStartTaskImmediateTaskLikeTests =
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Head branch was pushed to by a user without write access
|
@T-Gro |
|
The ifdef guard is correct, thanks for actioning this ! Pls let me know if I am owing any other reviews - I believe we might be finished with all the Async/Task/Value task improvements for NET11 by now? 🥇 👍 |
|
Thanks for shepherding these through, great to see them in!
@T-Gro these were my notes regarding potential additions fsharp/fslang-suggestions#1467 (comment) I personally have a fondness for The parallelDo for Async pops up in every codebase IME. And once you have Async.Parallel you want the Task equivalent and its easy to forget cancellation so I think that impl (plus the cancellable task ehancements in that other PR are subtle enough to help enough people - having to drag in FsToolkit.ErrorHandling is very annoying for a relatively common thing) All that said I do know your previous attitude has been to defer that from this batch of things - if that remains your stance, I might fork off a new pair of suggestions (this also would allow me to close the temp issues in TaskSeq thatnhave sat there annoying the RepoAssist bot for years!) |
Addresses the task start+await aspect of fsharp/fslang-suggestions#1284
See also fsharp/fslang-suggestions#1467
Checklist
Async.AwaitTaskoverloads which helps with CancellationToken passing, and a new warning fsharp/fslang-suggestions#1284 ?