SHARE
TWEET

Untitled

a guest Dec 13th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package
  3. {
  4.     import flash.display.Sprite;
  5.  
  6.     import nq.utils.task.TaskQueue;
  7.     import nq.utils.task.TaskQueueEvent;
  8.  
  9.  
  10.     /**
  11.      *
  12.      *
  13.      * @author  timothy.kovalev
  14.      */
  15.     public class TestQueue extends Sprite
  16.     {
  17.         public function TestQueue()
  18.         {
  19.             var queue:TaskQueue = new TaskQueue(5,false);
  20.  
  21.             var n:int = 20;
  22.             while(n--)
  23.             {
  24.                 queue.addTask(Math.random() > 0.5 ? new AsyncTask() : new SyncTask());
  25.             }
  26.  
  27.             queue.addEventListener(TaskQueueEvent.QUEUE_COMPLETE,onQueueComplete);
  28.             queue.addEventListener(TaskQueueEvent.TASK_COMPLETE,onTaskComplete);
  29.  
  30.             queue.start();
  31.         }
  32.  
  33.         private function onQueueComplete( event:TaskQueueEvent ):void
  34.         {
  35.             trace("Queue complete: /"+event.task+"/");
  36.         }
  37.  
  38.         private function onTaskComplete( event:TaskQueueEvent ):void
  39.         {
  40.             trace("Task complete: /"+event.task+"/");
  41.         }
  42.     }
  43. }
  44.  
  45. import flash.display.Shape;
  46. import flash.events.Event;
  47. import flash.events.EventDispatcher;
  48.  
  49. import nq.utils.task.IAsyncTask;
  50. import nq.utils.task.ITask;
  51.  
  52.  
  53. class AsyncTask extends EventDispatcher implements IAsyncTask
  54. {
  55.     private static var _instances:uint = 0;
  56.     private var _instance:uint = _instances++;
  57.  
  58.  
  59.     public function stop():void
  60.     {
  61.     }
  62.  
  63.     public function get priority():int
  64.     {
  65.         return 0;
  66.     }
  67.  
  68.     public function start():void
  69.     {
  70.         new Shape().addEventListener(Event.ENTER_FRAME,onComplete);
  71.     }
  72.  
  73.     private function onComplete( event:Event ):void
  74.     {
  75.         super.dispatchEvent(new Event(Event.COMPLETE))
  76.     }
  77.  
  78.  
  79.     override public function toString():String
  80.     {
  81.         return "{AsyncTask #"+_instance+"}"
  82.     }
  83. }
  84.  
  85. import flash.display.Shape;
  86. import flash.events.Event;
  87. import flash.events.EventDispatcher;
  88.  
  89. import nq.utils.task.IAsyncTask;
  90.  
  91.  
  92. class SyncTask extends EventDispatcher implements ITask
  93. {
  94.     private static var _instances:uint = 0;
  95.     private var _instance:uint = _instances++;
  96.  
  97.  
  98.     public function get priority():int
  99.     {
  100.         return 0;
  101.     }
  102.  
  103.     public function start():void
  104.     {
  105.         super.dispatchEvent(new Event(Event.COMPLETE))
  106.     }
  107.  
  108.     override public function toString():String
  109.     {
  110.         return "{SyncTask #"+_instance+"}"
  111.     }
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top