Skip to content

Instantly share code, notes, and snippets.

@Frikki

Frikki/esnextbin.md

Last active May 1, 2017
Embed
What would you like to do?
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>
console.clear()
import { fromEvent, from, concat } from 'most'
import events from 'events'
async function demo() {
const emitter = new events.EventEmitter()
const stream = fromEvent( 'event', emitter ).multicast()
const skipStream = stream.take( 1 )
skipStream.observe(x => console.log(`skip ${x}`))
await sleep(5000)
const result = concat( skipStream, stream.skip( 1 ) )
result.observe(console.log)
for ( let i = 1; i <= 5; i++ )
emitter.emit( 'event', i )
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
demo()
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"most": "1.2.2",
"undefined": "v4.5.0",
"babel-runtime": "6.23.0"
}
}
'use strict';
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var demo = function () {
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
var emitter, stream, skipStream, result, i;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
emitter = new _events2.default.EventEmitter();
stream = (0, _most.fromEvent)('event', emitter).multicast();
skipStream = stream.take(1);
skipStream.observe(function (x) {
return console.log('skip ' + x);
});
_context.next = 6;
return sleep(5000);
case 6:
result = (0, _most.concat)(skipStream, stream.skip(1));
result.observe(console.log);
for (i = 1; i <= 5; i++) {
emitter.emit('event', i);
}
case 9:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function demo() {
return ref.apply(this, arguments);
};
}();
var _most = require('most');
var _events = require('events');
var _events2 = _interopRequireDefault(_events);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.clear();
function sleep(ms) {
return new _promise2.default(function (resolve) {
return setTimeout(resolve, ms);
});
}
demo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment