Skip to content

Instantly share code, notes, and snippets.

@Fetz
Last active October 15, 2016 16:43
Show Gist options
  • Save Fetz/ec4404af2fbc0382ccd5198e2349b4e6 to your computer and use it in GitHub Desktop.
Save Fetz/ec4404af2fbc0382ccd5198e2349b4e6 to your computer and use it in GitHub Desktop.
rethinking asynchronous programming asynquence
$(document).ready(function(){
var rct = ASQ.react;
var $btn = $("#btn"),
$list = $("#list");
var clicks = rct.of();
$btn.click(function(evt) {
clicks.push('click');
});
var timers = rct.of();
setInterval(function() {
timers.push('tick');
}, 1000);
var merged = rct.merge(clicks, timers);
var distinct = rct.distinctUntilChanged(merged);
var msgs = rct.filter(distinct, function (msg) {
return msg !== 'tick';
});
msgs
.val(function () {
$list.append('<div>clicked!</div>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment