Flash Player is single threaded... which is why there isn't a "sleep"
command.  If you slept and didn't allow other code to execute... your
application would just freeze.  And that's not what you want.
I don't see where the problem is.  If I request a url... then get the
response.  I could just do the next request after I got the response.

Also you just setup a Timer to request on an interval.

On Fri, Aug 21, 2009 at 6:23 AM, Alexander Farber <
[email protected]> wrote:

> Hello,
>
> I have an AS3 app which continuously send HTTP requests to a server.
>
> If there is a HTTP request in progress already and it's not important
> (kind of "I am alive" event) I would like to cancel it.
>
> But if the ongoing request is important, I'd like to wait its completion
> before I send another one. I wonder how to implement this waiting
> properly, since AS3 doesn't seem to provide wait() and notify()
>
> Here is my code
>
>                private var request:URLRequest;
>                private var loader:URLLoader;
>                private var vars:URLVariables;
>                private var notImportant:Boolean;
> ....
>                loader.addEventListener(Event.COMPLETE, handleComplete);
> .....
>                private function fetch(event:Number, arg:String=null):void {
>                        // fix the caching problems in MSIE
>                        vars.mod = (new Date()).getTime();
>
>                        vars.event = event;
>                        if (arg != null)
>                                vars.arg = arg;
>                        else
>                                delete vars.arg;
>
>                        if (notImportant) {
>                                try {
>                                        loader.close();
>                                } catch (error:StreamError) {
>                                        trace(error);
>                                }
>                        } else {
>                                // XXX call wait() here? XXX
>                        }
>
>                        loader.load(request);
>                }
>
>               private function handleComplete(event:Event):void {
> ........
>                        // XXX call notify() at the end
>               }
>
> How could I solve this? I can't keep looping and checking
> some variable (like requestCompleted) because there is
> no sleep() function either and CPU usage would be high:
>
>             private function fetch(event:Number, arg:String=null):void {
> .....
>                      while (! requestCompleted) {
>                             // XXX call sleep(10) here XXX
>                     }
>
> Thank you for any suggestions
> Alex
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 

Cheers,
Nate
----------------------------------------
http://blog.natebeck.net
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to