Proposal Async "while" syntactic sugar #2599
Unanswered
BrianCArnold
asked this question in
Language Ideas
Replies: 2 comments
-
Note: you get this even with the original code. i.e.:
The variable, assignment, and invocation are all grouped together. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think you could get fairly close to your desired syntax by using a helper method and a lambda: var retrievedValue = await Meanwhile(RetrieveValueAsync(someRelatedValue), () =>
{
SynchronousMethod1();
SynchronousMethod2();
}); The implementation of static Task<T> Meanwhile<T>(Task<T> task, Action meanwhileAction)
{
meanwhileAction();
return task;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, to fire an async task and perform actions while it is completing, one usually does this:
var valueRetrievalTask = RetrieveValueAsync(someRelatedValue));
SynchronousMethod1();
SynchronousMethod2();
var retrievedValue = await valueRetrievalTask;
This requires that a task variable, and separates the assignment from the invocation of the async task.
I propose syntax similar to the following:
var retrievedValue = while(RetrieveValueAsync(someRelatedValue))
{
SynchronousMethod1();
SynchronousMethod2();
};
This allows the developer to see the assignment directly next to the invocation, and decoratively associates what executes during the async task.
Beta Was this translation helpful? Give feedback.
All reactions