PDA

View Full Version : jsonStore progress



rssk
7 Sep 2009, 8:12 AM
Hi all,

does anybody know, if there is any "waitMsg" function provided by jsonstore (while it's loading), or how I can implement some similar functionality.

Greets
rssk

FrankBerger
7 Sep 2009, 8:23 AM
My interest, too.

And ideally one, that lets the main process wait until the loading is finished so that subsequent actions, which rely on the loaded data, are suspended till loading is finished.

rssk
7 Sep 2009, 8:26 AM
My interest, too.

And ideally one, that lets the main process wait until the loading is finished so that subsequent actions, which rely on the loaded data, are suspended till loading is finished.

You can provide a "load" eventlistener, which is called after jsonstore loading completed.



jsonStore.on('load', yourFunc);

FrankBerger
7 Sep 2009, 8:53 AM
You can provide a "load" eventlistener, which is called after jsonstore loading completed.



jsonStore.on('load', yourFunc);

Well, thank you, but I doubt that this is the solution. I have to suspend all other processes until the loading is successfully finished. I don't see how this can be done by an event, which fires when loading is completed.

The "main process" continues ASFAIK, because loading is said to be asynchronous, thus I assume that it runs in its own process.

Mike Robinson
9 Sep 2009, 8:22 AM
Not exactly...

AJAX is event-driven. In other words, things are happening in a totally unpredictable sequence, and callback routines are defined which will be called on success or on failure. This is the only way that you know when something is finished, and the only way you have to know if it worked. You do not "wait on" anything.

When the JsonStore finishes loading itself, it will "fire an event" that your code can "listen for" as your only indication that the operation is complete. Your routine might wish to "fire an event" of your own devising, which other routines in your application are "listening for."

In other words, you do not "suspend all other processes until" the load is finished. Instead, you start the load and listen-for the completion event. When it comes, you "fire other events" that the various other parts of your program are listening for. Each of these listener callbacks will therefore (one at a time...) be called, "real soon now." Can't say exactly when; can't say in what order.

"It's cooperative multi-tasking in a Windows 3.1 sort of way ... but without Application.ProcessMessages." :)