Skip to content

Instantly share code, notes, and snippets.

@jasnell
Created July 30, 2022 18:55
Show Gist options
  • Save jasnell/811803ff59952098ee07b5239bb1ba00 to your computer and use it in GitHub Desktop.
Save jasnell/811803ff59952098ee07b5239bb1ba00 to your computer and use it in GitHub Desktop.
// Do this
const { writable, readable } = new TransformStream();
const writer = writable.getWriter();
writer.write('something');
writer.write('something');
writer.write('something');
// Here, you can use the writer's `.ready` promise to determine
// when backpressure has been relieved.
// Or this... (less desirable)
let writable;
const readable = new ReadableStream({
start(c) {
writable = new WritableStream({
write(chunk) {
c.enqueue(chunk);
}
}, {
highWaterMark: c.desiredSize
);
}
});
// Bad... don't do this
let controller;
const readable = new ReadableStream({
start(c) { controller = c }
});
c.enqueue('something');
c.enqueue('something');
c.enqueue('something'); // etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment