Skip to content

Commit 7766850

Browse files
committed
initial commit
0 parents  commit 7766850

9 files changed

+3432
-0
lines changed

.github/workflows/build.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build spec
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 16
18+
- run: npm ci
19+
- run: npm run build
20+
- run: npm run check-format

.github/workflows/deploy.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Deploy gh-pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: 16
17+
- run: npm ci
18+
- run: npm run build
19+
- uses: JamesIves/[email protected]
20+
with:
21+
branch: gh-pages
22+
folder: dist
23+
clean: true

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
dist
3+
4+
.DS_Store
5+
Desktop.ini
6+
._*
7+
Thumbs.db
8+
.Spotlight-V100
9+
.Trashes

DETAILS.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Details
2+
3+
There are number of decisions which could be made differently. This document attempts to catalog them along with the rationales for the choices currently made.
4+
5+
## Getting an iterator record from `this`
6+
7+
The added methods on `%IteratorPrototype%` assume that `this` is an iterator,
8+
and therefore use a new `GetIteratorDirect` method to acquire an iterator
9+
record. This means that code like `Iterator.syncPrototype.map.call([1, 2, 3], ...)`
10+
will not work.
11+
12+
## Passing the protocol
13+
14+
All added methods attempt to pass the values and calls they receive to whatever
15+
iterator they are wrapping. For example, `it.map(fn).next(5)` will call
16+
`it.next(5)` instead of `it.next()`. Additionally, calls like
17+
`it.map(fn).return()` will call upwards as well, to `it.return()`.
18+
19+
## Interface constraints
20+
21+
- The interface used to expose these methods must not clash with existing APIs.
22+
For example: `Array.prototype.map` or `Map.prototype.forEach` denying access
23+
to the interface.
24+
- It must work with everywhere an iteration can occur.
25+
For example: `%GeneratorFunction%.prototype.map` will not work because the
26+
interface has to be obtained from an explicit function call.
27+
`%GeneratorFunction%.prototype` has no symbolic API to get the iterator.

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Async Iterator Helpers
2+
3+
A proposal for several interfaces that will help with general usage and
4+
consumption of async iterators in ECMAScript.
5+
6+
This proposal was split out from [proposal-iterator-helpers](https://github.com/tc39/proposal-iterator-helpers) to resolve design questions related to parallelism, 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.
7+
8+
## Status
9+
10+
Authors: Gus Caplan, Michael Ficarra, Adam Vandolder, Jason Orendorff, Kevin Gibbons
11+
12+
Champions: Michael Ficarra, Kevin Gibbons
13+
14+
This proposal is at Stage 2 of [The TC39 Process](https://tc39.es/process-document/).
15+
16+
**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.
17+
18+
This proposal contains the following methods:
19+
20+
- `Iterator.prototype.toAsync`
21+
- `AsyncIterator.from`
22+
- `AsyncIterator.prototype`
23+
- `.map`
24+
- `.filter`
25+
- `.take`
26+
- `.drop`
27+
- `.flatMap`
28+
- `.reduce`
29+
- `.toArray`
30+
- `.forEach`
31+
- `.some`
32+
- `.every`
33+
- `.find`
34+
35+
See [proposal-iterator-helpers](https://github.com/tc39/proposal-iterator-helpers) for motivation and additional high-level descriptions for these methods.
36+
37+
## Parallelism
38+
39+
In the iterator-producing methods (`.map`, `.filter`, `.take`, `.drop`, and `.flatMap`), async helpers have the opportunity to support _parallelism_. For example, in the following code:
40+
41+
```js
42+
asyncIteratorOfUrls
43+
.map(u => fetch(u))
44+
45+
await Promise.all([
46+
x.next(),
47+
x.next(),
48+
])
49+
```
50+
51+
there could be two calls to `fetch` 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 simulaneous effects.
52+
53+
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.
54+
55+
### How can I access the new intrinsics?
56+
57+
This proposal introduces two new intrisic objects, in addition to the two added in the sync proposal. They can be accessed as follows:
58+
59+
```js
60+
const AsyncIteratorHelperPrototype = Object.getPrototypeOf(AsyncIterator.from([]).take(0));
61+
const WrapForValidAsyncIteratorPrototype = Object.getPrototypeOf(AsyncIterator.from({ async next(){} }));
62+
```

0 commit comments

Comments
 (0)