| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0f126d0 commit 617f2dc
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -570,6 +570,15 @@ This property contains the number of bytes (or objects) in the queue | |||
| 570 | 570 | ready to be written. The value provides introspection data regarding | |
| 571 | 571 | the status of the `highWaterMark`. | |
| 572 | 572 | ||
| 573 | + ##### `writable.writableNeedDrain` | ||
| 574 | + <!-- YAML | ||
| 575 | + added: REPLACEME | ||
| 576 | + --> | ||
| 577 | + | ||
| 578 | + * {boolean} | ||
| 579 | + | ||
| 580 | + Is `true` if the stream's buffer has been full and stream will emit `'drain'`. | ||
| 581 | + | ||
| 573 | 582 | ##### `writable.writableObjectMode` | |
| 574 | 583 | <!-- YAML | |
| 575 | 584 | added: v12.3.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -655,6 +655,11 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableEnded', { | |||
| 655 | 655 | get: function() { return this.finished; } | |
| 656 | 656 | }); | |
| 657 | 657 | ||
| 658 | + ObjectDefineProperty(OutgoingMessage.prototype, 'writableNeedDrain', { | ||
| 659 | + get: function() { | ||
| 660 | + return !this.destroyed && !this.finished && this[kNeedDrain]; | ||
| 661 | + } | ||
| 662 | + }); | ||
| 658 | 663 | ||
| 659 | 664 | const crlf_buf = Buffer.from('\r\n'); | |
| 660 | 665 | 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 | |
|---|---|---|---|
@@ -122,6 +122,10 @@ async function pump(iterable, writable, finish) { | |||
| 122 | 122 | } | |
| 123 | 123 | let error; | |
| 124 | 124 | try { | |
| 125 | + if (writable.writableNeedDrain === true) { | ||
| 126 | + await EE.once(writable, 'drain'); | ||
| 127 | + } | ||
| 128 | + | ||
| 125 | 129 | for await (const chunk of iterable) { | |
| 126 | 130 | if (!writable.write(chunk)) { | |
| 127 | 131 | if (writable.destroyed) return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -787,7 +787,12 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 787 | 787 | dest.emit('pipe', src); | |
| 788 | 788 | ||
| 789 | 789 | // Start the flow if it hasn't been started already. | |
| 790 | - if (!state.flowing) { | ||
| 790 | + | ||
| 791 | + if (dest.writableNeedDrain === true) { | ||
| 792 | + if (state.flowing) { | ||
| 793 | + src.pause(); | ||
| 794 | + } | ||
| 795 | + } else if (!state.flowing) { | ||
| 791 | 796 | debug('pipe resume'); | |
| 792 | 797 | src.resume(); | |
| 793 | 798 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -748,6 +748,14 @@ ObjectDefineProperties(Writable.prototype, { | |||
| 748 | 748 | } | |
| 749 | 749 | }, | |
| 750 | 750 | ||
| 751 | + writableNeedDrain: { | ||
| 752 | + get() { | ||
| 753 | + const wState = this._writableState; | ||
| 754 | + if (!wState) return false; | ||
| 755 | + return !wState.destroyed && !wState.ending && wState.needDrain; | ||
| 756 | + } | ||
| 757 | + }, | ||
| 758 | + | ||
| 751 | 759 | writableHighWaterMark: { | |
| 752 | 760 | get() { | |
| 753 | 761 | 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