Sdk: cascading await

Created on 26 Mar 2015  路  3Comments  路  Source: dart-lang/sdk

_This issue was originally filed by bl...@google.com_


Would it be possible to make the following work?

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

area-language closed-not-planned type-enhancement

All 3 comments

_Removed Type-Defect label._
_Added Type-Enhancement, Area-Language, Triaged labels._

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.

+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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matanlurey picture matanlurey  路  3Comments

DartBot picture DartBot  路  3Comments

xster picture xster  路  3Comments

55555Mohit55555 picture 55555Mohit55555  路  3Comments

SteveAlexander picture SteveAlexander  路  3Comments