Open trusktr opened 8 years ago
Besides, by merely having promises/async/await
in the language, can't we simply implement the other mechanisms (tasks and observables) using async/await, so that the following is possible?
import observable from 'somewhere'
let getStockPriceByName = observable(async function (stockName) {
let symbol = await getStockSymbol(stockName);
let price = await getStockPrice(symbol);
return price;
})
// Note, called without `await`:
let price = getStockPriceByName("Netflix");
let subscription = price.subscribe(price => console.log("The price of Netflix is ", price));
You mention in the README that
How does that verbose and hard to learn syntax compare to just
await
ingasync
functions in a loop, then simply breaking the loop in order "to create Task sequences that can be cancelled"?For example, assume some tool called TaskRunner, written with ES2016 async/await in mind (all promise based):
That (basically) does what you said, but is a ton more readable (of course, features can be added like error handling, pausing tasks, keeping track of running state and percent complete, etc).
Maybe I'm not seeing the benefit of the Tasks yet (thanks for writing about them for me to read about in the first place :smile: ).