Skip to content

Support await keyword in cascade notation #2762

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

Open
AAAbramenko opened this issue Jan 10, 2023 · 2 comments
Open

Support await keyword in cascade notation #2762

AAAbramenko opened this issue Jan 10, 2023 · 2 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@AAAbramenko
Copy link

Sometimes async methods of the class must be called sequentionally:

await loader.load('/file/path/1');
await loader.load('/file/path/2');

Support await in cascade notation will simplify this notation:

 loader
  ..await load('/file/path/1')
  ..await load('/file/path/2');

Awaited and unawated/sync calling methods can be mixed:

 loader
  ..setDestination('/destination/path') 
  ..await load('/file/path/1')
  ..await load('/file/path/2')
  ..removeFromSource(true);
@AAAbramenko AAAbramenko added the feature Proposed language feature that solves one or more problems label Jan 10, 2023
@Cat-sushi
Copy link

this is related to #25 and #1216 .

@lrhn
Copy link
Member

lrhn commented Jan 10, 2023

A suffix await seems like the best choice here.

The binding of prefix-cascade-await is iffy, and doesn't generalize to other chains.

loader..await load('file').save('file')

Does this await load('file') or does it await load('file').save('file').

And if save is also async, will you need ..await load('file').await save('file'), meaning this is not just about cascades.

Allowing loader..load('file').await.save('file').await will remove the ambiguity and follow the flow.

(It'd even allow a FutureOr<Null> foo = ...; bar(foo?.await); which doesn't await for null 😁)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

3 participants