Skip to content

Instantly share code, notes, and snippets.

@AzrizHaziq
Last active July 14, 2019 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AzrizHaziq/b9ea24dca0b24650854c09a569004f49 to your computer and use it in GitHub Desktop.
Save AzrizHaziq/b9ea24dca0b24650854c09a569004f49 to your computer and use it in GitHub Desktop.
Trying Javascript StreamReader
var stream = new ReadableStream({
start(controller) {
console.log(controller)
controller.enqueue('Hello');
controller.enqueue('12312312313123')
controller.close();
},
pull(controller) {
},
cancel(reason) {
}
})
var temp = '';
var reader = stream.getReader();
function readStream({ value, done }) {
if (done) {
console.log('>>>> done', temp)
return
}
console.log(value, done);
temp += value;
return reader.read().then(readStream)
}
reader.read().then(readStream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment