Currently, this is how I perform a query using node-mysql
client.query( sql, function( error, result ) {
console.dir( result );
});
I would like to do this synchronously, something like this
var result = client.querySync( sql );
console.dir( result );
I understand why blocking in node is bad, but I'm (almost) grown up enough to know when it's okay and when it's not. I only intend to make synchronous calls at the initialisation stage, outside of any event loops.
Does anybody know how I can achieve this please?
Edit...
Something along the lines of...
client.querySync = function( sql )
{
var called = false;
var result;
while ( typeof result == 'undefined' ) {
if ( ! called ) {
called = true;
this.query( sql, function( error, _result ) {
result = { error: error, result: _result };
});
};
}
return result;
};