| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e55d0ef commit 1650bcf
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -503,6 +503,16 @@ This property contains the number of bytes (or objects) in the queue | |||
| 503 | 503 | ready to be written. The value provides introspection data regarding | |
| 504 | 504 | the status of the `highWaterMark`. | |
| 505 | 505 | ||
| 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 | + | ||
| 506 | 516 | ##### writable.writableObjectMode | |
| 507 | 517 | <!-- YAML | |
| 508 | 518 | added: v12.3.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,6 +98,16 @@ Object.defineProperty(Duplex.prototype, 'writableLength', { | |||
| 98 | 98 | } | |
| 99 | 99 | }); | |
| 100 | 100 | ||
| 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 | + | ||
| 101 | 111 | // The no-half-open enforcer | |
| 102 | 112 | function onend() { | |
| 103 | 113 | // If the writable side ended, then we're ok. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -714,6 +714,16 @@ Object.defineProperty(Writable.prototype, 'writableObjectMode', { | |||
| 714 | 714 | } | |
| 715 | 715 | }); | |
| 716 | 716 | ||
| 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 | + | ||
| 717 | 727 | Writable.prototype.destroy = destroyImpl.destroy; | |
| 718 | 728 | Writable.prototype._undestroy = destroyImpl.undestroy; | |
| 719 | 729 | Writable.prototype._destroy = function(err, cb) { | |
| Original file line number | Diff line number | Diff 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 | + } | ||
| Original file line number | Diff line number | Diff 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments