-
Notifications
You must be signed in to change notification settings - Fork 4
Rationale
Yannick Spark ⚡️ edited this page May 10, 2017
·
1 revision
I created this lib when I tried to implement Tasks in JavaScript in order to understand how do they work.
I like using Promises but they have major design flaws IMHO :
- They run as soon as the promise is declared : what if I want to defer the computation ?
- They are async by default : i.e.
Promise.resolve(2)
always runs on the next tick - They are not cancellable (it's unfortunate that we can't cancel
window.fetch
http request when necessary)
Tasks happen to be really simple and have richer semantics than Promises :
- Tasks are pure : they do not perform any side-effect as long as they are not executed by calling
.fork()
. - Tasks make a clear separation between definition and execution, while Promises mix the two. @andrestaltz explained it way better than me in this comment
So I decided to replace Promises by Tasks in my code in order to separate pure data processing resulting of an async computation and side-effects.
I started this project after watching this talk about Observables.
The internals of Taskorama are similar to the one used in case explained in this video.