Skip to content

Instantly share code, notes, and snippets.

@JBreit
Created April 4, 2017 03:20
Show Gist options
  • Save JBreit/32dfcca2e26e2850cd3c025a147aca17 to your computer and use it in GitHub Desktop.
Save JBreit/32dfcca2e26e2850cd3c025a147aca17 to your computer and use it in GitHub Desktop.
/*global ReadableStream*/
(function () {
'use strict';
var interval;
var stream = new ReadableStream({
start: function (controller) {
interval = setInterval(function () {
var num = Math.random();
controller.enqueue(num);
if (num > 0.9) {
controller.close();
clearInterval(interval);
}
}, 1000);
},
cancel: function () {
clearInterval(interval);
}
});
console.log(stream);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment