Created
April 4, 2017 03:20
-
-
Save JBreit/32dfcca2e26e2850cd3c025a147aca17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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