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

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

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

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

17-
await(asyncfunction(){
17+
{
1818
constreadable=newReadable({objectMode: true,read(){}});
1919
readable.push(0);
2020
readable.push(1);
@@ -25,9 +25,9 @@ async function tests() {
2525
forawait(constdofiter){
2626
assert.strictEqual(d,1);
2727
}
28-
})();
28+
}
2929

30-
await(asyncfunction(){
30+
{
3131
console.log('read without for..await');
3232
constmax=5;
3333
constreadable=newReadable({
@@ -55,9 +55,9 @@ async function tests() {
5555

5656
constlast=awaititer.next();
5757
assert.strictEqual(last.done,true);
58-
})();
58+
}
5959

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

9696
constlast=awaititer.next();
9797
assert.strictEqual(last.done,true);
98-
})();
98+
}
9999

100-
await(asyncfunction(){
100+
{
101101
console.log('read without for..await with errors');
102102
constmax=3;
103103
constreadable=newReadable({
@@ -133,9 +133,9 @@ async function tests() {
133133
});
134134

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

138-
await(asyncfunction(){
138+
{
139139
console.log('call next() after error');
140140
constreadable=newReadable({
141141
read(){}
@@ -145,9 +145,9 @@ async function tests() {
145145
consterr=newError('kaboom');
146146
readable.destroy(newError('kaboom'));
147147
awaitassert.rejects(iterator.next.bind(iterator),err);
148-
})();
148+
}
149149

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

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

173-
await(asyncfunction(){
173+
{
174174
console.log('destroy sync');
175175
constreadable=newReadable({
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(asyncfunction(){
192+
{
193193
console.log('destroy async');
194194
constreadable=newReadable({
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(asyncfunction(){
224+
{
225225
console.log('destroyed by throw');
226226
constreadable=newReadable({
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(asyncfunction(){
247+
{
248248
console.log('destroyed sync after push');
249249
constreadable=newReadable({
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(asyncfunction(){
273+
{
274274
console.log('push async');
275275
constmax=42;
276276
letreaded=0;
@@ -293,9 +293,9 @@ async function tests() {
293293
}
294294

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

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

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

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

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

342-
await(asyncfunction(){
342+
{
343343
console.log('.next() on pipelined stream');
344344
constreadable=newReadable({
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
constr=newReadable({
366366
objectMode: true,
@@ -376,9 +376,9 @@ async function tests() {
376376
// eslint-disable-next-line no-unused-vars
377377
forawait(constbofr){
378378
}
379-
})();
379+
}
380380

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

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

413-
await(async()=>{
413+
{
414414
console.log('all next promises must be resolved on destroy');
415415
constr=newReadable({
416416
objectMode: true,
@@ -424,9 +424,9 @@ async function tests() {
424424
r.destroy();
425425
assert.deepStrictEqual(awaitc,{done: true,value: undefined});
426426
assert.deepStrictEqual(awaitd,{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
constr=newReadable({
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)