Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import nq.utils.task.TaskQueue;
- import nq.utils.task.TaskQueueEvent;
- /**
- *
- *
- * @author timothy.kovalev
- */
- public class TestQueue extends Sprite
- {
- public function TestQueue()
- {
- var queue:TaskQueue = new TaskQueue(5,false);
- var n:int = 20;
- while(n--)
- {
- queue.addTask(Math.random() > 0.5 ? new AsyncTask() : new SyncTask());
- }
- queue.addEventListener(TaskQueueEvent.QUEUE_COMPLETE,onQueueComplete);
- queue.addEventListener(TaskQueueEvent.TASK_COMPLETE,onTaskComplete);
- queue.start();
- }
- private function onQueueComplete( event:TaskQueueEvent ):void
- {
- trace("Queue complete: /"+event.task+"/");
- }
- private function onTaskComplete( event:TaskQueueEvent ):void
- {
- trace("Task complete: /"+event.task+"/");
- }
- }
- }
- import flash.display.Shape;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import nq.utils.task.IAsyncTask;
- import nq.utils.task.ITask;
- class AsyncTask extends EventDispatcher implements IAsyncTask
- {
- private static var _instances:uint = 0;
- private var _instance:uint = _instances++;
- public function stop():void
- {
- }
- public function get priority():int
- {
- return 0;
- }
- public function start():void
- {
- new Shape().addEventListener(Event.ENTER_FRAME,onComplete);
- }
- private function onComplete( event:Event ):void
- {
- super.dispatchEvent(new Event(Event.COMPLETE))
- }
- override public function toString():String
- {
- return "{AsyncTask #"+_instance+"}"
- }
- }
- import flash.display.Shape;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import nq.utils.task.IAsyncTask;
- class SyncTask extends EventDispatcher implements ITask
- {
- private static var _instances:uint = 0;
- private var _instance:uint = _instances++;
- public function get priority():int
- {
- return 0;
- }
- public function start():void
- {
- super.dispatchEvent(new Event(Event.COMPLETE))
- }
- override public function toString():String
- {
- return "{SyncTask #"+_instance+"}"
- }
- }
Add Comment
Please, Sign In to add comment