Skip to content

cascading await #23000

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

Closed
DartBot opened this issue Mar 26, 2015 · 4 comments
Closed

cascading await #23000

DartBot opened this issue Mar 26, 2015 · 4 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Mar 26, 2015

This issue was originally filed by [email protected]


Would it be possible to make the following work?

testDriver..await deleteAll()
  ..await createNew()
  ..await refresh();

@lrhn
Copy link
Member

lrhn commented Mar 26, 2015

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Mar 26, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
@lrhn lrhn added the closed-not-planned Closed as we don't intend to take action on the reported issue label Jun 22, 2018
@lrhn
Copy link
Member

lrhn commented Jun 22, 2018

I don't see this syntax happening. I'd put my money on #25986 instead, introducing a suffix form of await, so you could write, e.g.,

testDriver..deleteAll().await
  ..createNew().await
  ..refresh().await;

(or whatever syntax would be used for that).

The problem with allowing prefix operators to be used infix is that it's not clear how they bind.
If you write testDriver..await foo().bar(), are you awaiting foo() or foo().bar().
How about a..await b[42] or a..await b.foo()[42].

So, probably won't happen as this.

@subzero911
Copy link

+1, just made a mistake today:

final auth = await context.read<AuthStore>()..login();

this wouldn't work because I need to await login, not a read method
the only way is

final auth = context.read<AuthStore>();
await auth.login()

The desirable syntax is final auth = context.read<AuthStore>()..await login();... Things like login().await are counter-intuitive IMO.

@HannesGitH
Copy link

HannesGitH commented Feb 3, 2025

The problem with allowing prefix operators to be used infix is that it's not clear how they bind.
If you write testDriver..await foo().bar(), are you awaiting foo() or foo().bar().
How about a..await b[42] or a..await b.foo()[42].

how does that differ from normal await ? e.g.

if(await foo().bar()) // calls foo and awaits its bar
if((await foo()).bar()) // awaits foo and then calls its bar

and we know that, no ambiguity..
on the other hand a new syntax like

if(foo().bar().await.baz())

would probably confuse people as dart does not use .await as a postfix normally
and i dont really see how cascading differs from normal code/invocation


but, tbh, on the other hand I already find

final auth = await context.read<AuthStore>()..login();

somewhat ambigous already, as i thought cascading async calls would work similar to promise/future chaining à la

var auth;
await asyncGet<AuthStore>().then(init).then(login).then((a)=>auth=a)

which makes the whole call a future as soon as one part is async, and awaiting would await all calls and make

final auth = await asyncGet<AuthStore>()..init()..login();

work as @subzero911 (and I, which brought me here in the first place) thought (intuitively without actually thinking about it) it would

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants