Skip to content

Instantly share code, notes, and snippets.

@derekstavis
Last active November 4, 2015 13:44
Show Gist options
  • Save derekstavis/d68e679112282f074c6b to your computer and use it in GitHub Desktop.
Save derekstavis/d68e679112282f074c6b to your computer and use it in GitHub Desktop.
var Q = require('q')
, R = require('ramda');
function play(message) {
return Q.Promise(function (resolve, reject) {
setTimeout(function () {
console.log('Playing ' + message)
resolve();
}, 3000);
});
}
function playChain(messages) {
return R.reduce(
Q.when,
play(R.head(messages)),
R.map(
R.curry(R.partial)(play),
R.map(Array, R.tail(messages))
)
);
}
playChain(['Message 1', 'Message 2', 'Message 3', 'Message 4'])
.then(function () {
console.log('All messages played!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment