Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: How to synchronize easily 2 notifications ?  (Read 8248 times)
therewillbealight
Newbie
*
Posts: 5

 - therewillbealight@free.fr
View Profile Email
« on: November 26, 2008, 04:10:27 »

Hi,

I often have to synchrnoize 2 asychronous notifications;

For instance, on application startup, I begin loading assets, and meanwhile, I display a small menu for the user to choose the appropriate language. (this is juste an example, as this situation happened in multiple situations, I look for a generic solution)

So I have to launch a command once all is finiched, but only when assets will be loaded AND user will have clicked, but I cannot predict which one of these actions will be done first.

Is there a good and easy practice to make this, for 2 or more notifications that have to be synchronized ? Thanks a lot !  :D
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 26, 2008, 07:21:40 »

The issue you describe is the classic case for a splash screen.

In general, you don't want to present the UI to the user, thus inviting them to interact with it, until you are ready to either act immediately upon that input or accept and queue the input until such time as you are ready to process it.

You have the problem of needing to track the users click and remember it happened when assets are loaded. Or if it happens the other way round, knowing assets are already loaded when the click happens and to act accordingly. Both require knowledge of what came before.

But if you show a non-interactive splash screen at startup and then replace it with the ui when assets are loaded, you can then assume assets are loaded and act on the click right away.

-=Cliff>
Logged
therewillbealight
Newbie
*
Posts: 5

 - therewillbealight@free.fr
View Profile Email
« Reply #2 on: November 26, 2008, 07:33:42 »

Thanks a lot for your fast answer Cliff !

My problem here was that this was made on purpose to save a few loading seconds, as the site will be particularly heavy. So I was lloking for small tricks like this one to make the loading look shorter.

So by doing this, if the user takes 5 or 6 seconds to choose the languages he wishes to use, it would be 5 or 6 seconds of less to load assets, and it will seem shorter to him.

But more generally than this situation, it happened in other projets to have such cases, when 2 asychronous event need to happen before to send a special notification. So I was looking for a generic solution to solve this problem, not so specific to this startup case.

Do you think it could be a good practice to create a special Proxy for this, to store wheter a notification was trigger by both actors, and which will trigger a notification once it is the case ?

Thanks a lot for your fast answer !


Ben
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #3 on: November 26, 2008, 10:02:20 »

It seems there's a opportunity here for a new utility. Something that lets you input a bunch of notification names in an array, and then an onComplete notification to be sent once all the notes from the array are met.

something like:

:
// list of notifications to be complete
var listenFor:Array = [Constants.ONE_ACTION, Constants.OTHER_ACTION];

// this would be the utility, I'm bad with names ;)
someNewUtility.register(listenFor, Constants.RUN_ME_WHEN_COMPLETE);


The RUN_ME_WHEN_COMPLETE notification would then trigger whatever next step was to be taken after all the other actions were met. Maybe include an optional timeout so if it fails to meet all the actions it dispatches a timeout notification.
« Last Edit: November 26, 2008, 10:07:03 by jasonmac » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: November 26, 2008, 05:08:18 »

Coming extremely soon to a repo near you. Fleecie and I have been collaborating on a statemachine utility. I'm doing a demo as we speak. :)

-=Cliff>
Logged
therewillbealight
Newbie
*
Posts: 5

 - therewillbealight@free.fr
View Profile Email
« Reply #5 on: November 27, 2008, 03:29:05 »

Hi Cliff !

Wahou, that's really great, thanks a lot, let us know when we can try this cool utility  :) ! Thanks a lot for all the job that you've done so far and are doing, it helps us so much everyday, thanks a lot  :D !
Logged
Pages: [1]
Print