Why are javascript promises asynchronous when calling only synchronous functions?

The callback passed to a Promise constructor is always called synchronously, but the callbacks passed into then are always called asynchronously (you could use setTimeout with a delay of 0 in a userland implementation to achieve that). Simplifying your example (and giving the anonymous function’s names so I can refer to them) to: Promise.resolve().then(function callbackA … Read more

Can AFNetworking return data synchronously (inside a block)?

To block the execution of the main thread until the operation completes, you could do [operation waitUntilFinished] after it’s added to the operation queue. In this case, you wouldn’t need the return in the block; setting the __block variable would be enough. That said, I’d strongly discourage forcing asynchronous operations to synchronous methods. It’s tricky … Read more