| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -650,6 +650,7 @@ Writable.prototype.end = function(chunk, encoding, cb) { | |||
| 650 | 650 | ||
| 651 | 651 | function needFinish(state) { | |
| 652 | 652 | return (state.ending && | |
| 653 | + !state.destroyed && | ||
| 653 | 654 | state.constructed && | |
| 654 | 655 | state.length === 0 && | |
| 655 | 656 | !state.errored && | |
@@ -732,11 +733,18 @@ function prefinish(stream, state) { | |||
| 732 | 733 | function finishMaybe(stream, state, sync) { | |
| 733 | 734 | if (needFinish(state)) { | |
| 734 | 735 | prefinish(stream, state); | |
| 735 | - if (state.pendingcb === 0 && needFinish(state)) { | ||
| 736 | - state.pendingcb++; | ||
| 736 | + if (state.pendingcb === 0) { | ||
| 737 | 737 | if (sync) { | |
| 738 | - process.nextTick(finish, stream, state); | ||
| 739 | - } else { | ||
| 738 | + state.pendingcb++; | ||
| 739 | + process.nextTick((stream, state) => { | ||
| 740 | + if (needFinish(state)) { | ||
| 741 | + finish(stream, state); | ||
| 742 | + } else { | ||
| 743 | + state.pendingcb--; | ||
| 744 | + } | ||
| 745 | + }, stream, state); | ||
| 746 | + } else if (needFinish(state)) { | ||
| 747 | + state.pendingcb++; | ||
| 740 | 748 | finish(stream, state); | |
| 741 | 749 | } | |
| 742 | 750 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ fs.readFile(loc, common.mustSucceed((data) => { | |||
| 22 | 22 | const server = http2.createServer(); | |
| 23 | 23 | let client; | |
| 24 | 24 | ||
| 25 | - const countdown = new Countdown(3, () => { | ||
| 25 | + const countdown = new Countdown(2, () => { | ||
| 26 | 26 | server.close(); | |
| 27 | 27 | client.close(); | |
| 28 | 28 | }); | |
@@ -50,7 +50,6 @@ fs.readFile(loc, common.mustSucceed((data) => { | |||
| 50 | 50 | req.resume(); | |
| 51 | 51 | req.on('end', common.mustCall()); | |
| 52 | 52 | ||
| 53 | - req.on('finish', () => countdown.dec()); | ||
| 54 | 53 | const str = fs.createReadStream(loc); | |
| 55 | 54 | str.on('end', common.mustCall()); | |
| 56 | 55 | str.on('close', () => countdown.dec()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,16 +73,6 @@ server.on('request', common.mustCall(function(request, response) { | |||
| 73 | 73 | assert.throws(() => request.socket.pause = noop, errMsg); | |
| 74 | 74 | assert.throws(() => request.socket.resume = noop, errMsg); | |
| 75 | 75 | ||
| 76 | - request.stream.on('finish', common.mustCall(() => { | ||
| 77 | - setImmediate(() => { | ||
| 78 | - request.socket.setTimeout = noop; | ||
| 79 | - assert.strictEqual(request.stream.setTimeout, noop); | ||
| 80 | - | ||
| 81 | - assert.strictEqual(request.stream._isProcessing, undefined); | ||
| 82 | - request.socket._isProcessing = true; | ||
| 83 | - assert.strictEqual(request.stream._isProcessing, true); | ||
| 84 | - }); | ||
| 85 | - })); | ||
| 86 | 76 | response.stream.destroy(); | |
| 87 | 77 | })); | |
| 88 | 78 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,7 +125,7 @@ const assert = require('assert'); | |||
| 125 | 125 | duplex.removeListener('end', fail); | |
| 126 | 126 | duplex.removeListener('finish', fail); | |
| 127 | 127 | duplex.on('end', common.mustNotCall()); | |
| 128 | - duplex.on('finish', common.mustCall()); | ||
| 128 | + duplex.on('finish', common.mustNotCall()); | ||
| 129 | 129 | assert.strictEqual(duplex.destroyed, true); | |
| 130 | 130 | } | |
| 131 | 131 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -117,7 +117,7 @@ const assert = require('assert'); | |||
| 117 | 117 | transform.removeListener('end', fail); | |
| 118 | 118 | transform.removeListener('finish', fail); | |
| 119 | 119 | transform.on('end', common.mustCall()); | |
| 120 | - transform.on('finish', common.mustCall()); | ||
| 120 | + transform.on('finish', common.mustNotCall()); | ||
| 121 | 121 | } | |
| 122 | 122 | ||
| 123 | 123 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,8 +124,6 @@ const assert = require('assert'); | |||
| 124 | 124 | ||
| 125 | 125 | write.destroy(); | |
| 126 | 126 | ||
| 127 | - write.removeListener('finish', fail); | ||
| 128 | - write.on('finish', common.mustCall()); | ||
| 129 | 127 | assert.strictEqual(write.destroyed, true); | |
| 130 | 128 | } | |
| 131 | 129 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,3 +31,13 @@ const { Writable } = require('stream'); | |||
| 31 | 31 | w.write('asd'); | |
| 32 | 32 | w.destroy(); | |
| 33 | 33 | } | |
| 34 | + | ||
| 35 | + { | ||
| 36 | + const w = new Writable({ | ||
| 37 | + write() { | ||
| 38 | + } | ||
| 39 | + }); | ||
| 40 | + w.on('finish', common.mustNotCall()); | ||
| 41 | + w.end(); | ||
| 42 | + w.destroy(); | ||
| 43 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,9 +20,7 @@ for (const withPendingData of [ false, true ]) { | |||
| 20 | 20 | ||
| 21 | 21 | let chunksWritten = 0; | |
| 22 | 22 | let drains = 0; | |
| 23 | - let finished = false; | ||
| 24 | 23 | w.on('drain', () => drains++); | |
| 25 | - w.on('finish', () => finished = true); | ||
| 26 | 24 | ||
| 27 | 25 | function onWrite(err) { | |
| 28 | 26 | if (err) { | |
@@ -60,9 +58,5 @@ for (const withPendingData of [ false, true ]) { | |||
| 60 | 58 | assert.strictEqual(chunksWritten, useEnd && !withPendingData ? 1 : 2); | |
| 61 | 59 | assert.strictEqual(callbacks.length, 0); | |
| 62 | 60 | assert.strictEqual(drains, 1); | |
| 63 | - | ||
| 64 | - // When we used `.end()`, we see the 'finished' event if and only if | ||
| 65 | - // we actually finished processing the write queue. | ||
| 66 | - assert.strictEqual(finished, !withPendingData && useEnd); | ||
| 67 | 61 | } | |
| 68 | 62 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments