Imagine that I have a blocking function like this (the program will wait for the execution of random_operations
:
var result = random_operations(arg1,arg2);
But now I make this:
function Op() {
events.EventEmitter.call(this);
this.get= function(arg1, arg2)
{
this.arg1 = arg1;
this.arg2 = arg2;
this.result = random_operations(this.arg1,this.arg2);
this.emit('done', this.result);
}
}
Op.prototype.__proto__ = events.EventEmitter.prototype;
var do_job = new Op();
do_job.on('done', function(resulted) {
console.log('done '+ resulted);
});
dojob.get(_arg1, _arg2);
Using random_operations
like this means that node.js will not block? I am trying to understand how can I non-block the node.js.