-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add a Random Values Generator Demonstration #844
base: main
Are you sure you want to change the base?
Conversation
I am also working on another demo right now which is going to transform text into emojis, and would want to give a demos section a rehaul arranging the demos in a more friendlier, extensible and helpful format. |
* Starting the random values generation again after a certain period | ||
* @param {*} controller | ||
*/ | ||
async pull(controller) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessarily complicated. You don't need to track desiredSize
yourself. As long as you have called enqueue()
you can rely on the ReadableStream to call you back when there is no backpressure.
It would be simpler to do something like
pull(controller) {
if (maxValues && this.totalEnqueuedItemsCount >= maxValues) {
controller.close();
return;
}
let resolve;
const promise = new Promise(r => {
resolve = r;
});
setTimeout(() => {
controller.enqueue(randomValuesUint8Array(20));
++this.totalEnqueuedItemsCount;
resolve();
}, valueInterval);
return promise;
}
(untested).
* Writes a chunk to the span and appends it to the parent element | ||
* @param {*} chunk | ||
*/ | ||
async function writeChunk(chunk) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't need to be async as it performs no asynchronous operations. Also, as it is only called within write(), it might as well just be included in that function.
try { | ||
await writeChunk(chunk); | ||
return; | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary to catch the exception. If write() throws, the stream will errored automatically.
@@ -8,14 +8,17 @@ | |||
<dl> | |||
<dt><a href="append-child.html">Append child WritableStream</a> | |||
<dd>Piping through a series of transforms to a custom writable stream that appends children to | |||
the DOM. | |||
the DOM.</dd> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The end tag is not needed, see https://html.spec.whatwg.org/multipage/grouping-content.html#the-dd-element.
I find it tidier to leave it out.
Hi @ricea Thank you for reviewing this PR and sorry for not making the changes earlier. I'll make the changes now, I should also have that emoji stream converter on Github somewhere. I'll make a PR with that too. |
Adding a random values readable stream that generates a finites amount of random values using WebCrypto's getRandomValues method. This is a small demo, any suggestions to improve this demo are welcomed.
Here's a link to the demo's html page https://rawgit.com/abdulhannanali/streams/master/demos/random-values-stream/index.html