I just use callLater.

Royale should support all kinds of patterns.  I don't think there is any one 
winner.

HTH,
-Alex

On 1/21/19, 7:25 AM, "Harbs" <[email protected]> wrote:

    Every time I have to use Promises I want to pull out my hair. It must the 
the most unintuitive software pattern known to man.
    
    Async/await is somewhat better, but it’s just syntactic sugar and you end 
up dealing with Promises very often anyway. I also hate “magic”.
    
    The only other pattern I am familiar with when it comes to async execution 
(besides nested callbacks) is Monads and FP. Functional programming is another 
one of my aversions. I think it goes along with my aversion to math… ;-)
    
    I was wondering if there might be a “better” pattern for strongly typed 
languages such as AS3:
    1. A “manager" class which has methods which accepts “Execution” instances 
which implement an interface.
    2. The manager class would have methods for “addExection”, 
“addOrderedExecution” etc. The ordered execution could have the previous 
results automatically inserted into the subsequent execution.
    3. The manager class would have a done method which takes a callback with a 
“Result” object.
    4. It could also have an error method (or dispatch error events) in the 
case of errors.
    5. Each “Exectution” would have an “execute” method. It could let the 
manager know when it was done either by a callback or by dispatching an event.
    
    That would allow code like this:
    
    var manager:AsyncManager = new AsyncManager();
    manager.push(new ExecutionType1("foo"));
    manager.push(new ExecutionType2("foo"));
    manager.push(new ExecutionType3("foo"));
    manager.push(new ExecutionType4("foo"));
    manager.done(function(results:Array):void{
        for each(var res in results){
        trace(res);
        }
    });
    Manager.error(function(err:AsyncError):void{
        trace(err);
    }
    
    For ordered execution with results, it would be as simple as:
    var manager:AsyncManager = new AsyncManager();
    manager.pushOrdered(new ExecutionType1("foo"));
    manager.pushOrdered(new ExecutionType2("foo"));
    manager.pushOrdered(new ExecutionType3("foo"));
    manager.pushOrdered(new ExecutionType4("foo"));
    
    This feels much easier than promise.then, forced resolving and rejection of 
promises, etc.
    
    Thoughts?
    Harbs

Reply via email to