You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2022/03/02 15:36:36 UTC

[royale-asjs] branch develop updated: canceled needs to be handled better

This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 468c27c  canceled needs to be handled better
468c27c is described below

commit 468c27c7857e737f666e380c1e18b9a2500a7697
Author: Harbs <ha...@in-tools.com>
AuthorDate: Wed Mar 2 17:33:02 2022 +0200

    canceled needs to be handled better
---
 .../apache/royale/utils/async/CompoundAsyncTask.as | 293 +++++++++++----------
 .../royale/utils/async/SequentialAsyncTask.as      |   5 +-
 2 files changed, 157 insertions(+), 141 deletions(-)

diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/CompoundAsyncTask.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/CompoundAsyncTask.as
index 1b17f3e..e4e6215 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/CompoundAsyncTask.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/CompoundAsyncTask.as
@@ -18,157 +18,170 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.royale.utils.async
 {
-  import org.apache.royale.events.Event;
+	import org.apache.royale.events.Event;
 
-  /**
-   * The CompoundAsyncTask class allows running a number of AsyncTasks in parallel and resolves when they are done.
-   *  @langversion 3.0
-   *  @playerversion Flash 10.2
-   *  @playerversion AIR 2.6
-   *  @productversion Royale 0.9.6
-   */
-  public class CompoundAsyncTask extends AsyncTask
-  {
-    public function CompoundAsyncTask(tasks:Array=null)
-    {
-      super();
-      if(!tasks){
-        tasks = [];
-      }
-      this.tasks = tasks;
-      completedTasks = [];
-      failedTasks = [];
-    }
-    protected var tasks:Array;
+	/**
+	 * The CompoundAsyncTask class allows running a number of AsyncTasks in parallel and resolves when they are done.
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.6
+	 */
+	public class CompoundAsyncTask extends AsyncTask
+	{
+		public function CompoundAsyncTask(tasks:Array=null)
+		{
+			super();
+			if(!tasks){
+				tasks = [];
+			}
+			this.tasks = tasks;
+			completedTasks = [];
+			failedTasks = [];
+		}
+		protected var tasks:Array;
 
-    private var _failEarly:Boolean;
-    /**
-     * If <code>failEarly</code> is true, the task will fail as soon as the first subtask fails.
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion Royale 0.9.6
-     */
-    public function get failEarly():Boolean
-    {
-    	return _failEarly;
-    }
+		private var _failEarly:Boolean;
+		/**
+		 * If <code>failEarly</code> is true, the task will fail as soon as the first subtask fails.
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 */
+		public function get failEarly():Boolean
+		{
+			return _failEarly;
+		}
 
-    public function set failEarly(value:Boolean):void
-    {
-    	_failEarly = value;
-    }
-    /**
-     * Adds a task to the task list.
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion Royale 0.9.6
-     */
-    public function addTask(task:IAsyncTask):void{
-      tasks.push(task);
-    }
-    
-    protected var pendingTasks:Array;
+		public function set failEarly(value:Boolean):void
+		{
+			_failEarly = value;
+		}
+		/**
+		 * Adds a task to the task list.
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 */
+		public function addTask(task:IAsyncTask):void{
+			tasks.push(task);
+		}
+		
+		protected var pendingTasks:Array;
 
-    /**
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion Royale 0.9.6
-     *  @royalesuppresspublicvarwarning
-     */
-    public var completedTasks:Array;
-    /**
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion Royale 0.9.6
-     *  @royalesuppresspublicvarwarning
-     */
-    public var failedTasks:Array;
+		/**
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 *  @royalesuppresspublicvarwarning
+		 */
+		public var completedTasks:Array;
+		/**
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 *  @royalesuppresspublicvarwarning
+		 */
+		public var failedTasks:Array;
 
-    override public function run(data:Object=null):void
-    {
-      if(_status == "pending"){// don't allow running twice
-        return;
-      }
-      _status = "pending";
+		override public function run(data:Object=null):void
+		{
+			if(_status == "pending"){// don't allow running twice
+				return;
+			}
+			_status = "pending";
 
-      pendingTasks = tasks.slice();
+			pendingTasks = tasks.slice();
 
-      for each(var task:IAsyncTask in tasks){
-        task.done(handleDone);
-        task.run();
-      }
-    }
-    private function handleDone(task:IAsyncTask):void
-    {
-      if(_status != "pending")
-      {
-        return;
-      }
-      var idx:int = pendingTasks.indexOf(task);
-      pendingTasks.splice(idx,1);
-      switch(task.status){
-        case "complete":
-          completedTasks.push(task);
-          break;
-        // what to do for "mixed?
-        // We're assuming this is "failed" and adding the result to the failed tasks.
-        case "mixed":
-        case "failed":
-          failedTasks.push(task);
-          if(failEarly)
-          {
-            while(pendingTasks.length)
-            {
-              var pending:IAsyncTask = pendingTasks.pop();
-              pending.cancel();
-            }
-            fail();
-            return;
-          }
-          break;
-        default:// not sure why this would happen
-          throw new Error("Unknown task status");
-      }
-      if(pendingTasks.length == 0)
-      {
-        setFinalStatus();
-      }
-    }
-    protected function setFinalStatus():void
-    {
-      if(failedTasks.length == 0)
-      {
-        complete();
-      }
-      else if(completedTasks.length == 0)
-      {
-        fail();
-      }
-      else
-      {// Some passed and some failed -- Does this make sense?
-        _status = "mixed";
-        dispatchEvent(new Event("failed"));
-        dispatchEvent(new Event("complete"));
-        notifyDone();
-      }      
-    }
+			for each(var task:IAsyncTask in tasks){
+				task.done(handleDone);
+				task.run();
+			}
+		}
+		private function handleDone(task:IAsyncTask):void
+		{
+			if(_status != "pending" || _status == "canceled")
+			{
+				return;
+			}
+			var idx:int = pendingTasks.indexOf(task);
+			pendingTasks.splice(idx,1);
+			switch(task.status){
+				case "complete":
+					completedTasks.push(task);
+					break;
+				// what to do for "mixed?
+				// We're assuming this is "failed" and adding the result to the failed tasks.
+				case "mixed":
+				// canceled tasks are also added to failed tasks
+				case "canceled":
+				case "failed":
+					failedTasks.push(task);
+					if(failEarly)
+					{
+						fail();
+						cancelTasks();
+						return;
+					}
+					break;
+				default:// not sure why this would happen
+					throw new Error("Unknown task status");
+			}
+			if(pendingTasks.length == 0)
+			{
+				setFinalStatus();
+			}
+		}
+		protected function cancelTasks():void
+		{
+			while(pendingTasks.length)
+			{
+				var pending:IAsyncTask = pendingTasks.pop();
+				pending.cancel();
+				failedTasks.push(pending);
+			}
 
-    /**
-     * Static helper method for invoking the task in a single expression
-     *  @langversion 3.0
-     *  @productversion Royale 0.9.9
-     */
+		}
+		override public function cancel():void
+		{
+			cancelTasks();
+			super.cancel();
+		}
+		protected function setFinalStatus():void
+		{
+			if(failedTasks.length == 0)
+			{
+				complete();
+			}
+			else if(completedTasks.length == 0)
+			{
+				fail();
+			}
+			else
+			{// Some passed and some failed -- Does this make sense?
+				_status = "mixed";
+				dispatchEvent(new Event("failed"));
+				dispatchEvent(new Event("complete"));
+				notifyDone();
+			}
+		}
+
+		/**
+		 * Static helper method for invoking the task in a single expression
+		 *  @langversion 3.0
+		 *  @productversion Royale 0.9.9
+		 */
 		public static function execute(tasks:Array,callback:Function,failEarly:Boolean=false):void{
 			var task:CompoundAsyncTask = new CompoundAsyncTask(tasks);
 			task.failEarly = failEarly;
-      task.done(function():void{
-        callback(task);
-      });
+			task.done(function():void{
+				callback(task);
+			});
 			task.run();
 		}    
-  }
+	}
 }
\ No newline at end of file
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/SequentialAsyncTask.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/SequentialAsyncTask.as
index a715928..95e00f6 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/SequentialAsyncTask.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/async/SequentialAsyncTask.as
@@ -46,7 +46,7 @@ package org.apache.royale.utils.async
     }
     private function handleDone(task:IAsyncTask):void
     {
-      if(_status != "pending"){
+      if(_status != "pending" || _status == "canceled"){
         return;
       }
       switch(task.status){
@@ -56,6 +56,8 @@ package org.apache.royale.utils.async
         // what to do for "mixed?
         // We're assuming this is "failed" and adding the result to the failed tasks.
         case "mixed":
+				// canceled tasks are also added to failed tasks
+				case "canceled":
         case "failed":
           failedTasks.push(task);
           if(failEarly){
@@ -64,6 +66,7 @@ package org.apache.royale.utils.async
             return;
           }
           break;
+					return;
         default:// not sure why this would happen
           throw new Error("Unknown task status");