Last active
October 15, 2016 16:43
-
-
Save Fetz/ec4404af2fbc0382ccd5198e2349b4e6 to your computer and use it in GitHub Desktop.
rethinking asynchronous programming asynquence
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
$(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