Convert asynchronous/callback method to blocking/synchronous method

Is is possible to convert an asynchronous/callback based method in node to blocking/synchronous method?

I'm curious, more from a theoretical POV, than a "I have a problem to solve" POV.

I see how callback methods can be converted to values, via Q and the like, but calling Q.done() doesn't block execution.

node-sync module can halp you to do that. But please be careful, this is not node.js way.

While I would not recommend it, this can easy be done using some sort of busy wait. For instance:

var flag = false;
asyncFunction( function () { //This is a callback
    flag = true;
})

while (!flag) {}

The while loop will continuously loop until the callback has executed, thus blocking execution.

As you can imagine this would make your code very messy, so if you are going to do this (which I wouldn't recommend) you should make some sort of helper function to wrap your async function; similar to Underscore.js's Function functions, such as throttle. You can see exactly how these work by looking at the annotated source.