-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
stream: include strategy options on Readable #43515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 10 commits into
nodejs:main
from
Warkanlock:strategy_for_webstream
Jul 13, 2022
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c3050a6
stream: initial approach to include strategy options on Readable.toWeb()
Warkanlock b48a89d
stream: extend strategy option using an object to allow extensibility
Warkanlock 9eda83e
stream: fix typo on comment and change name of parameter in the docu…
Warkanlock bcff47a
stream: add unit test for strategy option
Warkanlock dd15dad
stream: added parameter size to calculate size of chunks if needed
Warkanlock f0f8798
stream: add better unit test to check if desireSize is being assigned
Warkanlock faf07cc
stream: remove unused imports
Warkanlock fa44cbf
stream: remove nested nernary and replace it with an inner function
Warkanlock 93d1582
stream: use an arrow function instead
Warkanlock 293be93
stream: refactor evaluateStrategyOrFallback method inspired by nit su…
Warkanlock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { Readable } = require('stream'); | ||
const assert = require('assert'); | ||
const { strictEqual } = require('assert'); | ||
|
||
{ | ||
// Strategy 2 | ||
const streamData = ['a', 'b', 'c', null]; | ||
|
||
// Fulfill a Readable object | ||
const readable = new Readable({ | ||
read: common.mustCall(() => { | ||
process.nextTick(() => { | ||
readable.push(streamData.shift()); | ||
}); | ||
}, streamData.length), | ||
}); | ||
|
||
// Use helper to convert it to a Web ReadableStream using ByteLength strategy | ||
const readableStream = Readable.toWeb(readable, { | ||
strategy: new ByteLengthQueuingStrategy({ highWaterMark: 1 }), | ||
}); | ||
|
||
assert(!readableStream.locked); | ||
readableStream.getReader().read().then(common.mustCall()); | ||
} | ||
|
||
{ | ||
// Strategy 2 | ||
const streamData = ['a', 'b', 'c', null]; | ||
|
||
// Fulfill a Readable object | ||
const readable = new Readable({ | ||
read: common.mustCall(() => { | ||
process.nextTick(() => { | ||
readable.push(streamData.shift()); | ||
}); | ||
}, streamData.length), | ||
}); | ||
|
||
// Use helper to convert it to a Web ReadableStream using Count strategy | ||
const readableStream = Readable.toWeb(readable, { | ||
strategy: new CountQueuingStrategy({ highWaterMark: 1 }), | ||
}); | ||
|
||
assert(!readableStream.locked); | ||
readableStream.getReader().read().then(common.mustCall()); | ||
} | ||
|
||
{ | ||
const desireSizeExpected = 2; | ||
|
||
const stringStream = new ReadableStream( | ||
{ | ||
start(controller) { | ||
// Check if the strategy is being assigned on the init of the ReadableStream | ||
strictEqual(controller.desiredSize, desireSizeExpected); | ||
controller.enqueue('a'); | ||
controller.enqueue('b'); | ||
controller.close(); | ||
}, | ||
}, | ||
new CountQueuingStrategy({ highWaterMark: desireSizeExpected }) | ||
); | ||
|
||
const reader = stringStream.getReader(); | ||
|
||
reader.read().then(common.mustCall()); | ||
reader.read().then(common.mustCall()); | ||
reader.read().then(({ value, done }) => { | ||
strictEqual(value, undefined); | ||
strictEqual(done, true); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.