-
Notifications
You must be signed in to change notification settings - Fork 431
Add new SetAction overload to avoid fire & forget silent error #2565
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,30 @@ public void SetAction(Func<ParseResult, CancellationToken, Task> action) | |
| }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets an asynchronous action to be run when the command is invoked. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// When possible, prefer using the <see cref="SetAction(Func{ParseResult, CancellationToken, Task})"/> overload | ||
| /// and passing the <see cref="CancellationToken"/> parameter to the async method(s) called by the action. | ||
| /// </remarks> | ||
| // Hide from intellisense, it's public to avoid the compiler choosing a sync overload | ||
| // for an async action (and fire and forget issue described in https://github.com/dotnet/command-line-api/issues/2562). | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you wanted to force folks to think about the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was my first idea, but then I realized that we should most likely not release new public @jonsequitur thoughts?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be simpler to differentiate the methods by name rather than using overloads, e.g.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
dotnet/Open-XML-SDK#1600 added ObsoleteAttribute to several new types and methods. There though, they intend to remove the attribute eventually, unlike here. |
||
| public void SetAction(Func<ParseResult, Task> action) | ||
| { | ||
| if (action is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(action)); | ||
| } | ||
|
|
||
| Action = new AnonymousAsynchronousCommandLineAction(async (context, cancellationToken) => | ||
| { | ||
| await action(context); | ||
| return 0; | ||
| }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets an asynchronous action when the command is invoked. | ||
| /// </summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.