Skip to content

Commit 49d651d

Browse files
committed
chore: Fix hard text wrapping in explainer
1 parent ff2c811 commit 49d651d

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

README.md

+35-33
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ Array.fromAsync and Promise.all, which have complementary control flows:
132132

133133
Also like `for await`, when given a sync-but-not-async iterable input, then
134134
Array.fromAsync will catch **only** the first rejection that its iteration
135-
reaches, and only if that rejection does **not** occur in a microtask before the
136-
iteration reaches and awaits for it. For more information, see [§ Errors][].
135+
reaches, and only if that rejection does **not** occur in a microtask before
136+
the iteration reaches and awaits for it. For more information, see
137+
[§ Errors][].
137138

138139
```js
139140
// `arr` will be `[ 0, 2, 4, 6 ]`.
@@ -149,16 +150,16 @@ const arr = await Promise.all(Array.from(genPromises(4)));
149150
```
150151

151152
### Non-iterable array-like inputs
152-
Array.fromAsync’s valid inputs are a superset of Array.from’s valid inputs. This
153-
includes non-iterable array-likes: objects that have a length property as well
154-
as indexed elements (similarly to Array.prototype.values). The return value is
155-
still a promise that will resolve to an array. If the array-like object’s
156-
elements are promises, then each accessed promise is awaited before its value is
157-
added to the new array.
153+
Array.fromAsync’s valid inputs are a superset of Array.from’s valid inputs.
154+
This includes non-iterable array-likes: objects that have a length property as
155+
well as indexed elements (similarly to Array.prototype.values). The return
156+
value is still a promise that will resolve to an array. If the array-like
157+
object’s elements are promises, then each accessed promise is awaited before
158+
its value is added to the new array.
158159

159160
One [TC39 representative’s opinion][issue #7 comment]: “[Array-likes are] very
160-
much not obsolete, and it’s very nice that things aren’t forced to implement the
161-
iterator protocol to be transformable into an Array.”
161+
much not obsolete, and it’s very nice that things aren’t forced to implement
162+
the iterator protocol to be transformable into an Array.”
162163

163164
[issue #7 comment]: https://github.com/tc39/proposal-array-from-async/issues/7#issuecomment-920299880
164165

@@ -193,8 +194,8 @@ by any other constructor. In that case, the final result will be the data
193194
structure created by that constructor (with no arguments), and with each value
194195
yielded by the input being assigned to the data structure’s numeric properties.
195196
(Symbol.species is not involved at all.) If the this receiver is not a
196-
constructor, then fromAsync creates an array as usual. This matches the behavior
197-
of Array.from.
197+
constructor, then fromAsync creates an array as usual. This matches the
198+
behavior of Array.from.
198199

199200
```js
200201
async function * asyncGen (n) {
@@ -287,9 +288,9 @@ Array.fromAsync(genError());
287288
```
288289

289290
When Array.fromAsync’s input is synchronous only (i.e., the input is not an
290-
async iterable), and when one of the input’s values is a promise that eventually
291-
rejects or has rejected, then iteration stops and Array.fromAsync’s returned
292-
promise will reject with the first such error.
291+
async iterable), and when one of the input’s values is a promise that
292+
eventually rejects or has rejected, then iteration stops and Array.fromAsync’s
293+
returned promise will reject with the first such error.
293294

294295
In this case, Array.fromAsync will catch and handle that first input rejection
295296
**only if** that rejection does **not** occur in a microtask before the
@@ -301,13 +302,14 @@ function * genRejection () {
301302
yield Promise.reject(err);
302303
}
303304

304-
// This returns a promise that will reject with `err`. There is **no** unhandled
305-
// promise rejection, because the rejection occurs in the same microtask.
305+
// This returns a promise that will reject with `err`. There is **no**
306+
// unhandled promise rejection, because the rejection occurs in the same
307+
// microtask.
306308
Array.fromAsync(genZeroThenRejection());
307309
```
308310

309-
Just like with `for await`, Array.fromAsync will **not** catch any rejections by
310-
the input’s promises whenever those rejections occur **before** the ticks in
311+
Just like with `for await`, Array.fromAsync will **not** catch any rejections
312+
by the input’s promises whenever those rejections occur **before** the ticks in
311313
which Array.fromAsync’s iteration reaches those promises.
312314

313315
This is because – like `for await` – Array.fromAsync **lazily** iterates over
@@ -317,10 +319,10 @@ developer needs to choose carefully between Array.fromAsync and Promise.all,
317319
which have complementary control flows (see [§ Sync-iterable
318320
inputs](#sync-iterable-inputs)).
319321

320-
For example, when a synchronous input contains two promises, the latter of which
321-
will reject before the former promise resolves, then Array.fromAsync will not
322-
catch that rejection, because it lazily reaches the rejecting promise only after
323-
it already has rejected.
322+
For example, when a synchronous input contains two promises, the latter of
323+
which will reject before the former promise resolves, then Array.fromAsync will
324+
not catch that rejection, because it lazily reaches the rejecting promise only
325+
after it already has rejected.
324326

325327
```js
326328
const numOfMillisecondsPerSecond = 1000;
@@ -395,16 +397,16 @@ asyncGen().toArray()
395397

396398
toArray overlaps with both Array.from and Array.fromAsync. This is okay. They
397399
can coexist. If we have to choose between having toArray and having fromAsync,
398-
then we should choose fromAsync. We already have Array.from. We should match the
399-
existing language precedent.
400+
then we should choose fromAsync. We already have Array.from. We should match
401+
the existing language precedent.
400402

401403
A [co-champion of iterable-helpers agrees][tc39/proposal-iterator-helpers#156]
402-
that we should have both or that we should prefer Array.fromAsync: “I remembered
403-
why it’s better for a buildable structure to consume an iterable than for an
404-
iterable to consume a buildable protocol. Sometimes building something one
405-
element at a time is the same as building it [more than one] element at a time,
406-
but sometimes it could be slow to build that way or produce a structure with
407-
equivalent semantics but different performance properties.”
404+
that we should have both or that we should prefer Array.fromAsync: “I
405+
remembered why it’s better for a buildable structure to consume an iterable
406+
than for an iterable to consume a buildable protocol. Sometimes building
407+
something one element at a time is the same as building it [more than one]
408+
element at a time, but sometimes it could be slow to build that way or produce
409+
a structure with equivalent semantics but different performance properties.”
408410

409411
[iterator-helpers]: https://github.com/tc39/proposal-iterator-helpers
410412
[tc39/proposal-iterator-helpers#156]: https://github.com/tc39/proposal-iterator-helpers/issues/156.
@@ -424,8 +426,8 @@ See [issue #8][] and [proposal-setmap-offrom][].
424426
[proposal-setmap-offrom]: https://github.com/tc39/proposal-setmap-offrom
425427

426428
### Async spread operator
427-
In the future, standardizing an async spread operator (like `[ 0, await ...v ]`)
428-
may be useful. This proposal leaves that idea to a **separate** proposal.
429+
In the future, standardizing an async spread operator (like `[ 0, await ...v
430+
]`) may be useful. This proposal leaves that idea to a **separate** proposal.
429431

430432
### Records and tuples
431433
The **[record/tuple] proposal** puts forward two new data types with APIs that

0 commit comments

Comments
 (0)