AsyncResult 3/3

Asynchronous Java Script

Is this JavaScript serial (killer :)) ever going to finish ? Well I am still having a lot of fun with this little JavaScript mechanism.

For AsyncResult 2/3 please click here.


First of all I have streamlined the AsyncResult itself , and even made it more future proof, by using proper JSON API, and future JSON names. Here is the very latest code:

 

Here and now, you might ask yourself a question : “Will I feel lucky, if I use this ?” . After all, ( for you too ) it is sometimes easier to “reinvent a hot water”, than to use other peoples “traps”.

In order to defend and promote my AsyncResult mechanism, I have made one certainly non-trivial example. A famous large-image download mechanism. Here I am actually using a well known jQuery mechanism to do it, but with the “twist”: it is used through my AsyncResult mechanism.

Why? To give more control to you.

How? By giving you one more intermediary event (or step), which happens while browser is waiting for large image to arrive. This you use to show that famous spinning gif, in order to improve “end user experience”.

Can this be done without AsyncResult? Certainly. But in a less encapsulated and less decoupled way.

Here is the testing js FIDDLE for you to try immediately.

For quicker understanding one should really start reading from the end. On calling spawn(), immediately an AsyncResult instance is returned and its toString() method is called, since we are here using it from inside a call to the dbj.log( “…some string …”) method. This is the jist of the software mechanism. Its perceived usage. This is where API succeeds or fails.

Above, jQuery is extensively used. I hope code is well documented and explained. Enjoy…

 

2 thoughts on “AsyncResult 3/3”

Comments are closed.