| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0d74226 commit 359a659
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -580,6 +580,15 @@ This property contains the number of bytes (or objects) in the queue | |||
| 580 | 580 | ready to be written. The value provides introspection data regarding | |
| 581 | 581 | the status of the `highWaterMark`. | |
| 582 | 582 | ||
| 583 | + ##### `writable.writableNeedDrain` | ||
| 584 | + <!-- YAML | ||
| 585 | + added: REPLACEME | ||
| 586 | + --> | ||
| 587 | + | ||
| 588 | + * {boolean} | ||
| 589 | + | ||
| 590 | + Is `true` if the stream's buffer has been full and stream will emit `'drain'`. | ||
| 591 | + | ||
| 583 | 592 | ##### `writable.writableObjectMode` | |
| 584 | 593 | <!-- YAML | |
| 585 | 594 | added: v12.3.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -660,6 +660,11 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableEnded', { | |||
| 660 | 660 | get: function() { return this.finished; } | |
| 661 | 661 | }); | |
| 662 | 662 | ||
| 663 | + ObjectDefineProperty(OutgoingMessage.prototype, 'writableNeedDrain', { | ||
| 664 | + get: function() { | ||
| 665 | + return !this.destroyed && !this.finished && this[kNeedDrain]; | ||
| 666 | + } | ||
| 667 | + }); | ||
| 663 | 668 | ||
| 664 | 669 | const crlf_buf = Buffer.from('\r\n'); | |
| 665 | 670 | OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,8 @@ ObjectDefineProperties(Duplex.prototype, { | |||
| 87 | 87 | ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableCorked'), | |
| 88 | 88 | writableEnded: | |
| 89 | 89 | ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableEnded'), | |
| 90 | + writableNeedDrain: | ||
| 91 | + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableNeedDrain'), | ||
| 90 | 92 | ||
| 91 | 93 | destroyed: { | |
| 92 | 94 | get() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,10 @@ async function pump(iterable, writable, finish) { | |||
| 123 | 123 | } | |
| 124 | 124 | let error; | |
| 125 | 125 | try { | |
| 126 | + if (writable.writableNeedDrain === true) { | ||
| 127 | + await EE.once(writable, 'drain'); | ||
| 128 | + } | ||
| 129 | + | ||
| 126 | 130 | for await (const chunk of iterable) { | |
| 127 | 131 | if (!writable.write(chunk)) { | |
| 128 | 132 | if (writable.destroyed) return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -783,7 +783,12 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 783 | 783 | dest.emit('pipe', src); | |
| 784 | 784 | ||
| 785 | 785 | // Start the flow if it hasn't been started already. | |
| 786 | - if (!state.flowing) { | ||
| 786 | + | ||
| 787 | + if (dest.writableNeedDrain === true) { | ||
| 788 | + if (state.flowing) { | ||
| 789 | + src.pause(); | ||
| 790 | + } | ||
| 791 | + } else if (!state.flowing) { | ||
| 787 | 792 | debug('pipe resume'); | |
| 788 | 793 | src.resume(); | |
| 789 | 794 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -805,6 +805,14 @@ ObjectDefineProperties(Writable.prototype, { | |||
| 805 | 805 | } | |
| 806 | 806 | }, | |
| 807 | 807 | ||
| 808 | + writableNeedDrain: { | ||
| 809 | + get() { | ||
| 810 | + const wState = this._writableState; | ||
| 811 | + if (!wState) return false; | ||
| 812 | + return !wState.destroyed && !wState.ending && wState.needDrain; | ||
| 813 | + } | ||
| 814 | + }, | ||
| 815 | + | ||
| 808 | 816 | writableHighWaterMark: { | |
| 809 | 817 | get() { | |
| 810 | 818 | return this._writableState && this._writableState.highWaterMark; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const Readable = require('_stream_readable'); | ||
| 6 | + const Writable = require('_stream_writable'); | ||
| 7 | + | ||
| 8 | + // Pipe should not continue writing if writable needs drain. | ||
| 9 | + { | ||
| 10 | + const w = new Writable({ | ||
| 11 | + write(buf, encoding, callback) { | ||
| 12 | + | ||
| 13 | + } | ||
| 14 | + }); | ||
| 15 | + | ||
| 16 | + while (w.write('asd')); | ||
| 17 | + | ||
| 18 | + assert.strictEqual(w.writableNeedDrain, true); | ||
| 19 | + | ||
| 20 | + const r = new Readable({ | ||
| 21 | + read() { | ||
| 22 | + this.push('asd'); | ||
| 23 | + } | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + w.write = common.mustNotCall(); | ||
| 27 | + | ||
| 28 | + r.pipe(w); | ||
| 29 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments