3 ms·
it’s possible to make sync function async it’s not the case other way round Is this terminology correct? I thought it is easier to make async functions syn
by pestaa 15y ago
it’s possible to make sync function async
it’s not the case other way round
Is this terminology correct? I thought it is easier to make async functions sync by blocking it, and harder to unblock a sync one. Am I confusing this with something else?
- gozala 15y agoSorry for confusion, I meant indeed a sync / async APIs. You could easily wrap sync function to give it an async API in order to chain with functions that had async APIs, but it's not really possible other way round (not in JS).
- lucian1900 15y agoI think the OP refers to the syntax/API for each. If you're already using async APIs, adding a sync one that runs in a separate thread won't change much. On the other hand, you need something like CPS or coroutines to cleanly use an async function in a program mostly using sync APIs. Of course, if you have the right tools (CPS/coroutines) you can make any async API look sync, as you said.
- gozala 15y agoI mainly was referring to JS where we don't have coroutines and there is no plans to have them either.
- shangaslammi 15y agoIt's a bit misleading way to put it, but more or less correct when talking about client-side JavaScript. There are essentially no blocking calls, so a "synchronous" function in this context just means a normal function which directly returns a value and "asynchronous" means a function that takes a callback. What the quoted bit boils down to is that any function that returns normally can be converted into a function that calls a callback, but not the other way around.