Last active
October 18, 2017 23:07
-
-
Save peter-leonov/1ca214f4ea9dc9422e1c58702ea2e3b4 to your computer and use it in GitHub Desktop.
Serial queue solution using lambda calculus.
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
const empty = | |
run => | |
run() | |
const enqueue = | |
(q, fn) => | |
next => | |
q(() => fn(next)) | |
let q = empty | |
q = enqueue(q, function(done){ | |
console.log('first'); | |
done(); | |
}); | |
q = enqueue(q, function(done){ | |
console.log('second'); | |
done(); | |
}); | |
q = enqueue(q, function(done){ | |
setTimeout(function(){ | |
console.log('third') | |
done() | |
}, 1000) | |
}); | |
q = enqueue(q, function(done){ | |
console.log('final task'); | |
done(); | |
}); | |
// runs the tasks | |
q(function(){ | |
console.log('done'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment