Add a Random Values Generator Demonstration#844
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.
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.
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.
Not necessary to catch the exception. If write() throws, the stream will errored automatically.
| <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.
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