AsyncResult 2/3


Ok, as promised I have extended and hopefully made more usefull, my AsyncResult mechanism, as presented in the first instalment of this javascript ‘soap’ 😉

For AsyncResult 1/3 please click here.

For AsyncResult 3/3 please click here.

Without further obfuscations here is the code :

I hope the comment on the top explains sufficiently well how to use this. In this version, one can pass any number of legal javascript arguments to the spawn function, to be passed onto the worker . And also one can assign a function which will be called “back” , from inside AsyncResult after worker execution has finished.

Here is the simple example of using AsyncResult and spawn() :

This mechanism enables use of one function to be called on finish, or use of many callback functions, one for each worker. In any case an id is now returned too, so that one can match spawn() returns and async and results.

( dbj.log() is my logging function. ) On executing the above testing code , the resulting log is this :

First line was printed immediately after spawn() returned. And the second line, from inside callback which was assigned to be called when w1(a,b,c) finishes.

I think, by now this AsyncResult mechanism may be even labelled as “useful” ?

Currently I plan to check if there is something somewhere. that I have overlooked. Maybe the whole code can be made simpler, more robust etc.
Also AsyncResult.prototype.toString() returns pitiful JSON string. Which must be made right.

Comments are closed.