Skip to content

Commit e04e854

Browse files
addaleaxBethGriggs
authored andcommitted
test: use blocks instead of async IIFE
Using an IIFE with async functions + await is equivalent to using a block scope (aside from scoping effects we don’t rely on), as far as I can tell. PR-URL: #24989 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
1 parent eb9e6e6 commit e04e854

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

test/parallel/test-stream-readable-async-iterators.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async function tests() {
1414
AsyncIteratorPrototype);
1515
}
1616

17-
await (async function() {
17+
{
1818
const readable = new Readable({ objectMode: true, read() {} });
1919
readable.push(0);
2020
readable.push(1);
@@ -25,9 +25,9 @@ async function tests() {
2525
for await (const d of iter) {
2626
assert.strictEqual(d, 1);
2727
}
28-
})();
28+
}
2929

30-
await (async function() {
30+
{
3131
console.log('read without for..await');
3232
const max = 5;
3333
const readable = new Readable({
@@ -55,9 +55,9 @@ async function tests() {
5555

5656
const last = await iter.next();
5757
assert.strictEqual(last.done, true);
58-
})();
58+
}
5959

60-
await (async function() {
60+
{
6161
console.log('read without for..await deferred');
6262
const readable = new Readable({
6363
objectMode: true,
@@ -95,9 +95,9 @@ async function tests() {
9595

9696
const last = await iter.next();
9797
assert.strictEqual(last.done, true);
98-
})();
98+
}
9999

100-
await (async function() {
100+
{
101101
console.log('read without for..await with errors');
102102
const max = 3;
103103
const readable = new Readable({
@@ -133,9 +133,9 @@ async function tests() {
133133
});
134134

135135
readable.destroy(new Error('kaboom'));
136-
})();
136+
}
137137

138-
await (async function() {
138+
{
139139
console.log('call next() after error');
140140
const readable = new Readable({
141141
read() {}
@@ -145,9 +145,9 @@ async function tests() {
145145
const err = new Error('kaboom');
146146
readable.destroy(new Error('kaboom'));
147147
await assert.rejects(iterator.next.bind(iterator), err);
148-
})();
148+
}
149149

150-
await (async function() {
150+
{
151151
console.log('read object mode');
152152
const max = 42;
153153
let readed = 0;
@@ -168,9 +168,9 @@ async function tests() {
168168
}
169169

170170
assert.strictEqual(readed, received);
171-
})();
171+
}
172172

173-
await (async function() {
173+
{
174174
console.log('destroy sync');
175175
const readable = new Readable({
176176
objectMode: true,
@@ -187,9 +187,9 @@ async function tests() {
187187
err = e;
188188
}
189189
assert.strictEqual(err.message, 'kaboom from read');
190-
})();
190+
}
191191

192-
await (async function() {
192+
{
193193
console.log('destroy async');
194194
const readable = new Readable({
195195
objectMode: true,
@@ -219,9 +219,9 @@ async function tests() {
219219

220220
assert.strictEqual(err.message, 'kaboom');
221221
assert.strictEqual(received, 1);
222-
})();
222+
}
223223

224-
await (async function() {
224+
{
225225
console.log('destroyed by throw');
226226
const readable = new Readable({
227227
objectMode: true,
@@ -242,9 +242,9 @@ async function tests() {
242242

243243
assert.strictEqual(err.message, 'kaboom');
244244
assert.strictEqual(readable.destroyed, true);
245-
})();
245+
}
246246

247-
await (async function() {
247+
{
248248
console.log('destroyed sync after push');
249249
const readable = new Readable({
250250
objectMode: true,
@@ -268,9 +268,9 @@ async function tests() {
268268

269269
assert.strictEqual(err.message, 'kaboom');
270270
assert.strictEqual(received, 1);
271-
})();
271+
}
272272

273-
await (async function() {
273+
{
274274
console.log('push async');
275275
const max = 42;
276276
let readed = 0;
@@ -293,9 +293,9 @@ async function tests() {
293293
}
294294

295295
assert.strictEqual(readed, received);
296-
})();
296+
}
297297

298-
await (async function() {
298+
{
299299
console.log('push binary async');
300300
const max = 42;
301301
let readed = 0;
@@ -323,9 +323,9 @@ async function tests() {
323323
}
324324

325325
assert.strictEqual(data, expected);
326-
})();
326+
}
327327

328-
await (async function() {
328+
{
329329
console.log('.next() on destroyed stream');
330330
const readable = new Readable({
331331
read() {
@@ -337,9 +337,9 @@ async function tests() {
337337

338338
const { done } = await readable[Symbol.asyncIterator]().next();
339339
assert.strictEqual(done, true);
340-
})();
340+
}
341341

342-
await (async function() {
342+
{
343343
console.log('.next() on pipelined stream');
344344
const readable = new Readable({
345345
read() {
@@ -358,9 +358,9 @@ async function tests() {
358358
} catch (e) {
359359
assert.strictEqual(e, err);
360360
}
361-
})();
361+
}
362362

363-
await (async () => {
363+
{
364364
console.log('iterating on an ended stream completes');
365365
const r = new Readable({
366366
objectMode: true,
@@ -376,9 +376,9 @@ async function tests() {
376376
// eslint-disable-next-line no-unused-vars
377377
for await (const b of r) {
378378
}
379-
})();
379+
}
380380

381-
await (async () => {
381+
{
382382
console.log('destroy mid-stream does not error');
383383
const r = new Readable({
384384
objectMode: true,
@@ -392,9 +392,9 @@ async function tests() {
392392
for await (const a of r) {
393393
r.destroy(null);
394394
}
395-
})();
395+
}
396396

397-
await (async () => {
397+
{
398398
console.log('all next promises must be resolved on end');
399399
const r = new Readable({
400400
objectMode: true,
@@ -408,9 +408,9 @@ async function tests() {
408408
r.push(null);
409409
assert.deepStrictEqual(await c, { done: true, value: undefined });
410410
assert.deepStrictEqual(await d, { done: true, value: undefined });
411-
})();
411+
}
412412

413-
await (async () => {
413+
{
414414
console.log('all next promises must be resolved on destroy');
415415
const r = new Readable({
416416
objectMode: true,
@@ -424,9 +424,9 @@ async function tests() {
424424
r.destroy();
425425
assert.deepStrictEqual(await c, { done: true, value: undefined });
426426
assert.deepStrictEqual(await d, { done: true, value: undefined });
427-
})();
427+
}
428428

429-
await (async () => {
429+
{
430430
console.log('all next promises must be resolved on destroy with error');
431431
const r = new Readable({
432432
objectMode: true,
@@ -457,7 +457,7 @@ async function tests() {
457457
}
458458
assert.strictEqual(e, err);
459459
})()]);
460-
})();
460+
}
461461
}
462462

463463
// to avoid missing some tests if a promise does not resolve

0 commit comments

Comments
 (0)