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))))
Hi! Great gist! Thank you.
And I have a question :)
Promise.allwill return array with results. Anddoseqwill call<!on each channel and you will get data one-by-one, right?But what if I need both results at the same time? Is there any way to get them?
I tried to resolve this with
async/merge, but it will return a channel, from which I must get values by one at the time to.