Closed reggi closed 9 years ago
Task uses the same argument order Either
uses, so Left/Error
is the first argument, Right/Success
is the second.
I'm not a fan of optional arguments. I think they cause more problems than they solve (and they prevent VM optimisations too, because you get different shapes in your function call :/). But you can always create an utility function for that:
function run(task, cc) {
task.fork(
function(error){ throw error },
function(value){ cc(value) }
)
}
run(Task.of(1), console.log.bind(console))
run(Task.rejected(1), console.log.bind(console))
The next version of Task
will separate things into Tasks
and Futures
, so it might have a simpler interface for running tasks in general (and it'll make the resource handling part simpler/more correct).
I'd really like it if
.fork
worked with one function just works and if there's an error it gets thrown (just like a promise would)And I'd love support for a catch
Note:
.fork
is very similar to.then
with a promise, the odd thing is that for promisesYou can see the the rejectedHandler is the second argument.
.fork
's arguments are reversed, which is really confusing.