I am currently executing a query using node-mysql
client.query( sql, function( error, result ) { console.dir( result ); });
I would like to do it synchronously, something like this
var result = client.querySync( sql ); console.dir( result );
I understand why the lock in node is bad, but I (almost) grew enough to know when everything is in order and when not. I only intend to make synchronous calls in the initialization phase outside of any event loop.
Does anyone know how I can achieve this?
Edit ...
Something along the lines ...
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; };
source share