Comparing ES7 and core.async
ES7 | core.async |
---|---|
async function() {...} |
(fn [] (go ...)) |
await ... |
(<! ...) |
await* or Promise.all(...) |
(doseq [c ...] (<! c)) |
Calling foo
returns a promise receiving value 1
:
async function foo () {
return 1;
}
Calling foo
returns a channel receiving value 1
:
(defn foo []
(go 1))
bar
is parked until foo
has finished:
async function bar() {
await foo();
}
bar
's go-block is parked until foo
has finished:
(defn bar []
(go
(<! (foo))))
baz
waits for foo
and bar
to complete:
async function baz() {
await Promise.all([foo(), bar()]);
}
(defn baz []
(go
(doseq [c [(foo) (bar)]]
(<! c))))
@shaunlebron Thanks for this. One important difference: uncaught exceptions in core.async get eaten and will not pass the go-block boundary. You must be sure to catch them yourself and come up with your own error handling convention. Async/await converts uncaught exceptions into a rejected promise, so you don't have to worry about it.