-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add Async.AwaitTask
overloads which helps with CancellationToken passing, and a new warning
#1284
Comments
I personally don't think that emitting warning from compiler is a good idea, it makes it aware of a very specific type as well as twisting the promise of optional parameters (i.e. Optional parameters are optional, except CancellationToken). This, however, should be a great analyzer for when we will be working on analyzers sdk. |
What is your opinion of just the additional overloads? Those could be added without the warning. |
TL;DR the Async.AwaitTask semantics are problematic, and adding more operations that implicitly couple to those semantics is therefore something that should not proceed until that's resolved. I arrived at the same thing, with the name I don't love the name Also, as noted in fsprojects/FSharp.AWS.DynamoDB#65, anything that can assist with making correct propagation of CTs the unobtrusive non-issue it is in F# app code bases would be very welcome (Even considering making a CT argument mandatory for the Task layer in FSharp.AWS.DynamoDB in order to force the issue). However I'd say that in practice, the actual calls of Task-returning methods are many levels deep into libraries (probably in an area that is using the |
There's a long standing issue in the fsharp repo about this problem: dotnet/fsharp#2127 |
I propose we add two
Async.AwaitTask
overloads:Async.AwaitTask(makeTask: CancellationToken -> Task<'a>) -> Async<'a>
Async.AwaitTask(makeTask: CancellationToken -> Task) -> Async<unit>
I also propose that an accompanying compiler warning be added. In situations where the task method could have been provided a
CancellationToken
(either via an optional parameter or a separate overload), the compiler should emit a warning.The warning could say something like: "This task-returning method can accept a CancellationToken (through an overload or optional parameter), but is not provided one. Please either use Async.AwaitTask(makeTask: CancellationToken -> Task<'a>), or capture and provide a CancellationToken manually."
Surely there are better wordings for such a warning; improvements are welcome.
For example, the following, which forgets to pass a CancellationToken, would now emit a warning:
To make the warning go away, you could use the new overload:
Or capture and pass it yourself:
The existing way of approaching this problem in F# is ...
For the new method, you can write your own extensions today:
Pros and Cons
The advantages of making this adjustment to F# are:
The disadvantages of making this adjustment to F# are:
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: