4 ms·
2 main reasons: 1. If some nested function is async/await, all the callers (and whole graph) need to be converted to async/await. I feel that language shouldn't
by kidstrack 9y ago
2 main reasons:
1. If some nested function is async/await, all the callers (and whole graph) need to be converted to async/await. I feel that language shouldn't force programmer to do this type of tedious work.
2. It's not compatible with some browsers, only via Babel
- cdata 9y ago#1 is a misleading claim. An async function returns a promise when called, which can be used in any non-async context.
- Matthias247 9y agoI think the claim was: One async function (which of course returns a Promise under the hood) forces all surrounding functions to be also asynchronous (return a promise). Of course you could start an async operation from any function -> Just call the async function and ignore the result. But in order to do something with the result and return a transformed version of it the surrounding function has to be async (return a Promise, accept callbacks, etc) too. Maybe the confusion was the async here has two meanings: 1. asynchronous in general, which means it doesn't return a result immediately, but returns it through a Promise which is fulfilled later or a callback. 2. Using the async/await syntax. As we all agree this one is just sugar around Promises.
- sametmax 9y agoIn JS async/await returns a promise. In Python you have asyncio.ensure_future() to schedule coroutines. You can always call async code from sync code.
- camus2 9y ago> If some nested function is async/await, all the callers (and whole graph) need to be converted to async/await Is totally false. You can await on any promise, the method called doesn't have to be an async function. And you can resolve any async function through promises as well. > 2. It's not compatible with some browsers, only via Babel async/await is part of the the ES spec, which browsers have to follow to be compliant with ES spec.