made with esnextbin
Last active
December 28, 2016 15:09
-
-
Save briancavalier/adf027d348abf45746b244297ec19d24 to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</body> | |
</html> |
This file contains 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
import { concatMap, concat, just, from, join, constant, filter, delay, periodic, timestamp, observe } from 'most' | |
const alwaysIgnore = () => false | |
const bufferingThrottle = (minInterval, stream) => | |
concatMap(x => concat(just(x), filter(alwaysIgnore, delay(minInterval, just(null)))), stream) | |
const s = join(constant(periodic(1000), from([1, 2, 3, 4]))) | |
// original stream is bursty, 4 events, nothing, 4 events, nothing, etc. | |
// observe(x => console.log(x), timestamp(s)) | |
// Use bufferingThrottle to add some space between events without dropping any | |
observe(x => console.log(x), timestamp(bufferingThrottle(200, s))) |
This file contains 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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"most": "1.1.1" | |
} | |
} |
This file contains 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
'use strict'; | |
var _most = require('most'); | |
var alwaysIgnore = function alwaysIgnore() { | |
return false; | |
}; | |
var bufferingThrottle = function bufferingThrottle(minInterval, stream) { | |
return (0, _most.concatMap)(function (x) { | |
return (0, _most.concat)((0, _most.just)(x), (0, _most.filter)(alwaysIgnore, (0, _most.delay)(minInterval, (0, _most.just)(null)))); | |
}, stream); | |
}; | |
var s = (0, _most.join)((0, _most.constant)((0, _most.periodic)(1000), (0, _most.from)([1, 2, 3, 4]))); | |
// original stream is bursty, 4 events, nothing, 4 events, nothing, etc. | |
// observe(x => console.log(x), timestamp(s)) | |
// Use bufferingThrottle to add some space between events without dropping any | |
(0, _most.observe)(function (x) { | |
return console.log(x); | |
}, (0, _most.timestamp)(bufferingThrottle(200, s))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment