Re:Show HN: Nsynjs – JS engine with stoppable threads and wi...
by kidstrack on Wednesday May 24, 2017 @01:54AM
(#14407859)
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
[ Parent
| on HN ]
Re:Show HN: Nsynjs – JS engine with stoppable threads and wi...
by sametmax on Wednesday May 24, 2017 @02:03AM
(#14407899)
In 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.
Re:Show HN: Nsynjs – JS engine with stoppable threads and wi...
by camus2 on Wednesday May 24, 2017 @10:48AM
(#14410384)
> 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.
Re:Show HN: Nsynjs – JS engine with stoppable threads and wi...
by cdata on Wednesday May 24, 2017 @01:59AM
(#14407878)
#1 is a misleading claim. An async function returns a promise when called, which can be used in any non-async context.
Re:Show HN: Nsynjs – JS engine with stoppable threads and wi...
by Matthias247 on Wednesday May 24, 2017 @02:34AM
(#14407978)
I 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.