-
Notifications
You must be signed in to change notification settings - Fork 205
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
Support Synchronous evaluation of FutureOr #726
Comments
cc @rrousselGit |
Thinking about it, I wonder if it's not for backward compatibility with JS? I don't see any other explanation. Although I'd expect dart2js compiler to be able to convert Dart await calls to something like: let futureOr;
let result;
if (futureOr instanceof Promise) {
result = await futureOr;
} else {
result = futureOr;
} |
It's not for compatibility with JS. The original discussion in Dart 1 was whether to allow Dart 2 is more strictly typed, but we still allow you to await non-futures. Some would argue that that was a mistake, but it had the advantage that it works with That all means that the current behavior of |
Would it make sense to have a This would avoid having to use something like SynchronousFuture from Flutter. We can technically do: if (futureOr is int)
print(futureOr + 9);
else
print((await futureOr) + 9); But there's no way to factorize it without resorting to something similar to It's not a critical feature though. |
Feature request
When we have a variable
FutureOr<int> futureOr
,await futureOr
should run synchronously when the variable is not aFuture
(see https://stackoverflow.com/q/59213196/6509751).Current situation
At the moment, you need to use the following code if you want to run the evaluation synchronously when possible:
The text was updated successfully, but these errors were encountered: