-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Asynchronous Iterations #11326
Comments
FWIW, TypeScript currently emits garbage if you try to I'd expect it to throw an error until async iteration is properly supported. |
One suggestion I think can make the asynchronous workflows easier to read:
For example
|
@imetallica Eeh, I don't think it's a good idea. The main goal of Typescript is to provide type safety and analysis for JS. Therefore, it shouldn't deviate from ECMAScript standard if it is possible. |
The asynchronous iterations proposal is now in stage 3, so it should be safe to support that in TypeScript now. Currently, a function may be a generator or an async function, but it cannot be both. The asynchronous iteration proposal removes this restriction. Here's an example from their readme:
Types
Generator functions declare several interfaces:
Async generators return promises instead of their
IteratorResult
, and use a new symbol,Symbol.asyncIterator
:Emit
I guess that this would require another helper function to downlevel to ES2015, similar to the one used for async functions. Yield and await expression would both be replaced by yield expression, so they need to be decorated with some tag, like
yield ['await', promise]
forawait promise
.for-await-of
The proposal also introduces a new loop. An example from their readme:
This iterates over the
[Symbol.asyncIterator]()
object and awaits the value of.next()
, similar to a for-of loop. This loop can only be used in async functions.The text was updated successfully, but these errors were encountered: