Re:Write logic, not mechanics
by pestaa on Thursday April 19, 2012 @07:06AM
(#3862347)
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?
[ Parent
| on HN ]
Re:Write logic, not mechanics
by shangaslammi on Thursday April 19, 2012 @07:22AM
(#3862394)
It'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.
Re:Write logic, not mechanics
by lucian1900 on Thursday April 19, 2012 @07:19AM
(#3862383)
I 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.
I mainly was referring to JS where we don't have coroutines and there is no plans to have them either.
Sorry 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).