Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Methods for working with async iterators in ECMAScript

NotificationsYou must be signed in to change notification settings

tc39/proposal-async-iterator-helpers

A proposal for several interfaces that will help with general usage andconsumption of async iterators in ECMAScript.

This proposal was split out fromproposal-iterator-helpers to resolve design questions related to concurrency (see below), which are not relevant to sync helpers. Many design questions (including choice of methods) were discussed and decided in that respository, and its readme should be read first.

Status

Authors: Gus Caplan, Michael Ficarra, Adam Vandolder, Jason Orendorff, Kevin Gibbons

Champions: Michael Ficarra, Kevin Gibbons

This proposal is at Stage 2 ofThe TC39 Process.

This proposal is in the process of being revised. The core set of helpers and their high-level API is unlikely to change, but the underlying specification mechanism will likely be radically revised.

This proposal contains the following methods:

  • Iterator.prototype.toAsync
  • AsyncIterator.from
  • AsyncIterator.prototype
    • .map
    • .filter
    • .take
    • .drop
    • .flatMap
    • .reduce
    • .toArray
    • .forEach
    • .some
    • .every
    • .find

Seeproposal-iterator-helpers for motivation and additional high-level descriptions for these methods.

Concurrency

In the iterator-producing methods (.map,.filter,.take,.drop, and.flatMap), async helpers have the opportunity to supportconcurrency. For example, in the following code:

x=asyncIteratorOfUrls.map(u=>fetch(u))awaitPromise.all([x.next(),x.next(),])

there could be two calls tofetch running at once. For this to work, the helpers have to be explicitly designed to support this. The original design of this proposal instead implemented the helpers as essentially async generators, which buffer calls to.next rather than allowing multiple calls to have simultaneous effects.

This proposal is being revised to support at least the above use case. The exact details of what that looks like for each helper are not yet decided.

How can I access the new intrinsics?

This proposal introduces two new intrisic objects, in addition to the two added in the sync proposal. They can be accessed as follows:

constAsyncIteratorHelperPrototype=Object.getPrototypeOf(AsyncIterator.from([]).take(0));constWrapForValidAsyncIteratorPrototype=Object.getPrototypeOf(AsyncIterator.from({asyncnext(){}}));

About

Methods for working with async iterators in ECMAScript

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp