[Flashcoders] Missing wait(), notify(), sleep() in AS3

2009-08-21 Thread Alexander Farber
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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Missing wait(), notify(), sleep() in AS3

2009-08-21 Thread Nate Beck
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 
alexander.far...@gmail.com 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
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 

Cheers,
Nate

http://blog.natebeck.net
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Missing wait(), notify(), sleep() in AS3

2009-08-21 Thread Ashim D'Silva
Just call your next function in two places...
I don't really see the problem. If it's not important just cancel it can
call the new function, otherwise, wait for the complete event to fire and
then call it...

Ashim

The Random Lines
My online portfolio
www.therandomlines.com


2009/8/21 Alexander Farber alexander.far...@gmail.com

 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();

 DO NEW CALL


} 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

 DO NEW CALL


   }

 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
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders