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 1650bcf

Browse filesBrowse files
zero1fivetargos
authored andcommitted
stream: add writableFinished
add a new getter to duplex stream to replace the property `this .writableState.finished` of the object that inherited duplex. Refs: #445 PR-URL: #28007 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent e55d0ef commit 1650bcf
Copy full SHA for 1650bcf

File tree

Expand file treeCollapse file tree

5 files changed

+90
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+90
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/stream.md‎

Copy file name to clipboardExpand all lines: doc/api/stream.md
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,16 @@ This property contains the number of bytes (or objects) in the queue
503503
ready to be written. The value provides introspection data regarding
504504
the status of the `highWaterMark`.
505505

506+
##### writable.writableFinished
507+
<!-- YAML
508+
added: v12.4.0
509+
-->
510+
511+
* {boolean}
512+
513+
Is `true` if all data has been flushed to the underlying system. After
514+
the [`'finish'`][] event has been emitted.
515+
506516
##### writable.writableObjectMode
507517
<!-- YAML
508518
added: v12.3.0
Collapse file

‎lib/_stream_duplex.js‎

Copy file name to clipboardExpand all lines: lib/_stream_duplex.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ Object.defineProperty(Duplex.prototype, 'writableLength', {
9898
}
9999
});
100100

101+
Object.defineProperty(Duplex.prototype, 'writableFinished', {
102+
// Making it explicit this property is not enumerable
103+
// because otherwise some prototype manipulation in
104+
// userland will fail
105+
enumerable: false,
106+
get() {
107+
return this._writableState.finished;
108+
}
109+
});
110+
101111
// The no-half-open enforcer
102112
function onend() {
103113
// If the writable side ended, then we're ok.
Collapse file

‎lib/_stream_writable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_writable.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,16 @@ Object.defineProperty(Writable.prototype, 'writableObjectMode', {
714714
}
715715
});
716716

717+
Object.defineProperty(Writable.prototype, 'writableFinished', {
718+
// Making it explicit this property is not enumerable
719+
// because otherwise some prototype manipulation in
720+
// userland will fail
721+
enumerable: false,
722+
get() {
723+
return this._writableState.finished;
724+
}
725+
});
726+
717727
Writable.prototype.destroy = destroyImpl.destroy;
718728
Writable.prototype._undestroy = destroyImpl.undestroy;
719729
Writable.prototype._destroy = function(err, cb) {
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { Duplex } = require('stream');
5+
const assert = require('assert');
6+
7+
// basic
8+
{
9+
// Find it on Duplex.prototype
10+
assert(Duplex.prototype.hasOwnProperty('writableFinished'));
11+
}
12+
13+
// event
14+
{
15+
const duplex = new Duplex();
16+
17+
duplex._write = (chunk, encoding, cb) => {
18+
// The state finished should start in false.
19+
assert.strictEqual(duplex.writableFinished, false);
20+
cb();
21+
};
22+
23+
duplex.on('finish', common.mustCall(() => {
24+
assert.strictEqual(duplex.writableFinished, true);
25+
}));
26+
27+
duplex.end('testing finished state', common.mustCall(() => {
28+
assert.strictEqual(duplex.writableFinished, true);
29+
}));
30+
}
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { Writable } = require('stream');
5+
const assert = require('assert');
6+
7+
// basic
8+
{
9+
// Find it on Writable.prototype
10+
assert(Writable.prototype.hasOwnProperty('writableFinished'));
11+
}
12+
13+
// event
14+
{
15+
const writable = new Writable();
16+
17+
writable._write = (chunk, encoding, cb) => {
18+
// The state finished should start in false.
19+
assert.strictEqual(writable.writableFinished, false);
20+
cb();
21+
};
22+
23+
writable.on('finish', common.mustCall(() => {
24+
assert.strictEqual(writable.writableFinished, true);
25+
}));
26+
27+
writable.end('testing finished state', common.mustCall(() => {
28+
assert.strictEqual(writable.writableFinished, true);
29+
}));
30+
}

0 commit comments

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