Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Last active December 28, 2016 15:09
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 briancavalier/adf027d348abf45746b244297ec19d24 to your computer and use it in GitHub Desktop.
Save briancavalier/adf027d348abf45746b244297ec19d24 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!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>
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)))
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"most": "1.1.1"
}
}
'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