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

Appearance settings

Commit 7c4f9a3

Browse filesBrowse files
ronagtargos
authored andcommitted
stream: allow calling callback before promise
Refs: #39535 PR-URL: #40772 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2ea08e9 commit 7c4f9a3
Copy full SHA for 7c4f9a3

File tree

Expand file treeCollapse file tree

4 files changed

+39
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+39
-27
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/destroy.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/destroy.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ function constructNT(stream) {
292292
then.call(
293293
result,
294294
function() {
295-
process.nextTick(onConstruct, null);
295+
if (!called) {
296+
process.nextTick(onConstruct, null);
297+
}
296298
},
297299
function(err) {
298-
process.nextTick(onConstruct, err);
300+
if (!called) {
301+
process.nextTick(onConstruct, err);
302+
}
299303
});
300304
}
301305
}
Collapse file

‎lib/internal/streams/writable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,14 @@ function callFinal(stream, state) {
699699
then.call(
700700
result,
701701
function() {
702-
process.nextTick(onFinish, null);
702+
if (!called) {
703+
process.nextTick(onFinish, null);
704+
}
703705
},
704706
function(err) {
705-
process.nextTick(onFinish, err);
707+
if (!called) {
708+
process.nextTick(onFinish, err);
709+
}
706710
});
707711
}
708712
}
Collapse file

‎test/parallel/test-stream-construct-async-error.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-construct-async-error.js
+1-23Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ const {
99
const { setTimeout } = require('timers/promises');
1010
const assert = require('assert');
1111

12-
{
13-
class Foo extends Duplex {
14-
async _construct(cb) {
15-
// eslint-disable-next-line no-restricted-syntax
16-
await setTimeout(common.platformTimeout(1));
17-
cb();
18-
throw new Error('boom');
19-
}
20-
}
21-
22-
const foo = new Foo();
23-
foo.on('error', common.expectsError({
24-
message: 'boom'
25-
}));
26-
foo.on('close', common.mustCall(() => {
27-
assert(foo._writableState.constructed);
28-
assert(foo._readableState.constructed);
29-
}));
30-
}
31-
3212
{
3313
class Foo extends Duplex {
3414
async _destroy(err, cb) {
@@ -98,9 +78,7 @@ const assert = require('assert');
9878

9979
const foo = new Foo();
10080
foo.write('test', common.mustCall());
101-
foo.on('error', common.expectsError({
102-
code: 'ERR_MULTIPLE_CALLBACK'
103-
}));
81+
foo.on('error', common.mustNotCall());
10482
}
10583

10684
{
Collapse file
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const {
5+
Duplex,
6+
} = require('stream');
7+
const { setTimeout } = require('timers/promises');
8+
9+
{
10+
class Foo extends Duplex {
11+
async _final(callback) {
12+
// eslint-disable-next-line no-restricted-syntax
13+
await setTimeout(common.platformTimeout(1));
14+
callback();
15+
}
16+
17+
_read() {}
18+
}
19+
20+
const foo = new Foo();
21+
foo._write = common.mustCall((chunk, encoding, cb) => {
22+
cb();
23+
});
24+
foo.end('test', common.mustCall());
25+
foo.on('error', common.mustNotCall());
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.