JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/cujojs/most/master/dist/most.js"></script>
JavaScript
"use strict";
function log(s) {
var line = document.createElement('div');
line.textContent = s;
document.body.appendChild(line);
}
function foo(clb) {
setTimeout(function() {
clb('A');
}, (Math.random()*100)|0);
}
function bar(clb) {
setTimeout(function() {
clb('B');
}, (Math.random()*100)|0);
}
function baz(clb) {
setTimeout(function() {
clb('C');
}, (Math.random()*100)|0);
}
/**
change the code below to provide a guaranteed output as follows:
A
B
C
**/
function fromArray(src) {
return function * () {
while (src.length) {
yield new Promise(src.shift());
}
}
}
most
.generate(fromArray([foo, bar, baz]))
.observe(log);