Skip to content
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

Async variant #4

Closed
yuchi opened this issue Sep 15, 2017 · 5 comments
Closed

Async variant #4

yuchi opened this issue Sep 15, 2017 · 5 comments

Comments

@yuchi
Copy link

yuchi commented Sep 15, 2017

Brought from a comment to the original proposal Gist by @Jamesernator:

Will there also be an async variant in this proposal, or would that be a consideration for later proposals? e.g.

const file = do async { // or async do or something
    const response = await fetch('some-resource.txt') // the main purpose of a async do would be to allow await
    response.text()
}
// file is the promise response response.text()

Please note that the discussion went on on the original thread.

@jakearchibald
Copy link

This would work really well for functions that take promises. Eg fetchEvent.respondWith in service worker, or event.waitUntil which is used in a few specs like the web locks proposal.

So instead of:

event.respondWith(async function() {
  const cachedResponse = await caches.match();
  return cachedResponse || fetch(event.request);
}());

Folks could do:

event.respondWith(do async {
  const cachedResponse = await caches.match();
  cachedResponse || fetch(event.request);
});

@be5invis
Copy link

be5invis commented Nov 3, 2018

Also there could be do * {} for generators/monads.

do * {
 const x = yield get()
 yield set(x +1);
}

@qubyte
Copy link

qubyte commented Nov 27, 2018

Came here inspired by upcoming Rust async blocks. 👍

@atg
Copy link

atg commented Dec 21, 2018

Seems to me it should be async do rather than do async, for symmetry with async function() { } etc.

@bakkot
Copy link
Collaborator

bakkot commented Jan 30, 2021

I think this is a great idea, and I've begun a proposal for this. Feel free to follow along there.

@bakkot bakkot closed this as completed Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants