Open
Description
A common UI problem is to want to make potentially asynchronous code synchronous if possible, to avoid flickers where progress indicators show only for a frame or two.
While there are solutions to this problem, the issue is, those solutions are strictly incompatible with async
/await
– decreasing the code readability quite a bit.
Proposal
To solve the problem of async/await being incompatible with code-paths that are potentially synchronous, we could introduce an async
variant that returns a FutureOr
Meaning we could write:
FutureOr<int> multiplyByTwo() keyword {
FutureOr<int> futureOr;
T value = await futureOr;
return value * 2;
}
With this variant, await
may execute synchronously (when it currently would always be async). Meaning that the previous snippet would be equivalent to doing:
FutureOr<int> multiplyByTwo() {
FutureOr<int> futureOr;
if (futureOr is Futureint>)
return futureOr.then((value) => value * 2);
return value * 2;
}