From 36640f5af2dac2d508b50783af0f0ebbafc50c44 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Fri, 10 Mar 2017 11:15:35 +0100 Subject: [PATCH 1/9] cancel state added to IAsyncCallback --- src/hex/control/async/AsyncCallback.hx | 56 +++++- src/hex/control/async/IAsyncCallback.hx | 1 + test/hex/control/AsyncCallbackTest.hx | 228 +++++++++++++++++++++--- 3 files changed, 254 insertions(+), 31 deletions(-) diff --git a/src/hex/control/async/AsyncCallback.hx b/src/hex/control/async/AsyncCallback.hx index 71501ce..d2de9b9 100644 --- a/src/hex/control/async/AsyncCallback.hx +++ b/src/hex/control/async/AsyncCallback.hx @@ -17,12 +17,14 @@ class AsyncCallback implements IAsyncCallback var _completeResponder : Array>; var _failResponder : ArrayVoid>; + var _cancelResponder : ArrayVoid>; var _result : AsyncResult; public function new() { this._completeResponder = []; this._failResponder = []; + this._cancelResponder = []; this._result = Result.WAITING; AsyncCallback._map.set( this, true ); @@ -30,9 +32,9 @@ class AsyncCallback implements IAsyncCallback public static function get( callback : Callback> ) : AsyncCallback { - var handler = new AsyncCallback(); - callback.invoke( handler._complete ); - return handler; + var acb = new AsyncCallback(); + callback.invoke( acb._complete ); + return acb; } macro public function whenComplete( ethis : Expr, clazz : Expr ) : ExprOf> @@ -72,6 +74,22 @@ class AsyncCallback implements IAsyncCallback return this; } + public function onCancel( onCancel : Void->Void ) : AsyncCallback + { + switch( this._result ) + { + case Result.WAITING: + this._cancelResponder.push( onCancel ); + + case Result.CANCELLED: + onCancel(); + + case _: + } + + return this; + } + function _complete( result : AsyncResult ) : Void { switch( result ) @@ -82,6 +100,9 @@ class AsyncCallback implements IAsyncCallback case Result.FAILED( error ): this._doFail( error ); + case Result.CANCELLED: + this._doCancel(); + case _: } } @@ -100,7 +121,7 @@ class AsyncCallback implements IAsyncCallback } else { - throw new IllegalStateException( 'AsyncCallback is disposed' ); + throw new IllegalStateException( 'AsyncCallback cannot be completed, it is disposed' ); } } @@ -118,15 +139,35 @@ class AsyncCallback implements IAsyncCallback } else { - throw new IllegalStateException( 'AsyncCallback is disposed' ); + throw new IllegalStateException( 'AsyncCallback cannot be failed, it is disposed' ); + } + } + + function _doCancel() : Void + { + if ( AsyncCallback._map.exists( this ) ) + { + this._result = Result.CANCELLED; + for ( responder in this._cancelResponder ) + { + responder(); + } + + this._dispose(); + } + else + { + throw new IllegalStateException( 'AsyncCallback cannot be cancelled, it is disposed' ); } } function _dispose() : Void { AsyncCallback._map.remove( this ); - this._completeResponder = null; - this._failResponder = null; + + this._completeResponder = null; + this._failResponder = null; + this._cancelResponder = null; } } @@ -135,6 +176,7 @@ enum Result WAITING; DONE( result : T ); FAILED( e : Exception ); + CANCELLED; } private class AsyncCallbackUtil diff --git a/src/hex/control/async/IAsyncCallback.hx b/src/hex/control/async/IAsyncCallback.hx index 31b4758..dbf6d5a 100644 --- a/src/hex/control/async/IAsyncCallback.hx +++ b/src/hex/control/async/IAsyncCallback.hx @@ -10,4 +10,5 @@ interface IAsyncCallback { function onComplete( onComplete : Callback ) : IAsyncCallback; function onFail( onFail : Exception->Void ) : IAsyncCallback; + function onCancel( onCancel : Void->Void ) : IAsyncCallback; } \ No newline at end of file diff --git a/test/hex/control/AsyncCallbackTest.hx b/test/hex/control/AsyncCallbackTest.hx index ade49c1..4a5d071 100644 --- a/test/hex/control/AsyncCallbackTest.hx +++ b/test/hex/control/AsyncCallbackTest.hx @@ -22,43 +22,93 @@ class AsyncCallbackTest { var result : String; var error : Exception; + var cancel = false; //test completion - _loadString( false ).onComplete( function(r) {result = r;} ).onFail( function(e) {error = e;} ); + _loadString( Result.DONE( 'test' ) ) + .onComplete( function(r) result = r ) + .onFail( function(e) error = e ) + .onCancel( function() cancel = true ); Assert.equals( 'test', result ); Assert.isNull( error ); + Assert.isFalse( cancel ); //test failure result = null; error = null; - _loadString( true ).onComplete( function(r) { result = r; } ).onFail( function(e) { error = e; } ); + cancel = false; + + _loadString( Result.FAILED( new Exception( 'message' ) ) ) + .onComplete( function(r) result = r ) + .onFail( function(e) error = e ) + .onCancel( function() cancel = true ); Assert.isInstanceOf( error, Exception ); Assert.equals( 'message', error.message ); Assert.isNull( result ); + Assert.isFalse( cancel ); + + //test cancel + result = null; + error = null; + cancel = false; + + _loadString( Result.CANCELLED ) + .onComplete( function(r) result = r ) + .onFail( function(e) error = e ) + .onCancel( function() cancel = true ); + + Assert.isTrue( cancel ); + Assert.isNull( result ); + Assert.isNull( error ); } @Test( 'Test without argument result' ) public function testWithoutArgumentResult() : Void { - var result : String; + var result : Nothing; var error : Exception; + var cancel = false; //test completion - _load( false ).onComplete( function() {result = 'test';} ).onFail( function(e) {error = e;} ); + _load( Result.DONE( Nothing ) ) + .onComplete( function() result = Nothing ) + .onFail( function(e) error = e ) + .onCancel( function() cancel = true ); - Assert.equals( 'test', result ); + Assert.equals( Nothing, result ); Assert.isNull( error ); + Assert.isFalse( cancel ); //test failure result = null; error = null; - _load( true ).onComplete( function() { result = 'test'; } ).onFail( function(e) { error = e; } ); + cancel = false; + + _load( Result.FAILED( new Exception( 'message' ) ) ) + .onComplete( function(r) result = r ) + .onFail( function(e) error = e ) + .onCancel( function() cancel = true ); Assert.isInstanceOf( error, Exception ); Assert.equals( 'message', error.message ); Assert.isNull( result ); + Assert.isFalse( cancel ); + + //test cancel + result = null; + error = null; + cancel = false; + + _load( Result.CANCELLED ) + .onComplete( function(r) result = r ) + .onFail( function(e) error = e ) + .onCancel( function() cancel = true ); + + Assert.isTrue( cancel ); + Assert.isNull( result ); + Assert.isNull( error ); } @Test( 'Test completion twice' ) @@ -109,6 +159,30 @@ class AsyncCallbackTest Assert.isInstanceOf( error, IllegalStateException ); } + @Test( 'Test cancel twice' ) + public function tesCancelTwice() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Result.CANCELLED ); + handler( Result.CANCELLED ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + @Test( 'Test completion and failure at the same time' ) public function testCompletionAndFailureAtTheSameTime() : Void { @@ -133,6 +207,126 @@ class AsyncCallbackTest Assert.isInstanceOf( error, IllegalStateException ); } + @Test( 'Test failure and completion at the same time' ) + public function testFailureAndCompletionAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( new Exception( 'message' ) ); + handler( Nothing ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test completion and cancel at the same time' ) + public function testCompletionAndCancelAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Nothing ); + handler( Result.CANCELLED ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test completion and cancel at the same time' ) + public function testCancelAndCompletionAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Result.CANCELLED ); + handler( Nothing ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test failure and cancel at the same time' ) + public function testFailureAndCancelAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( new Exception( 'message' ) ); + handler( Result.CANCELLED ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test cancel and failure at the same time' ) + public function testCancelAndFailureAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Result.CANCELLED ); + handler( new Exception( 'message' ) ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + @Test( "test simple lambda chaining" ) public function testSimpleLambdaChaining() { @@ -214,38 +408,24 @@ class AsyncCallbackTest , collection, "collection content should be the same" ); } - static function _load( failure : Bool ) : IAsyncCallback + static function _load( result : Result ) : IAsyncCallback { return AsyncCallback.get ( function ( handler : Handler ) { - if ( !failure ) - { - handler( Nothing ); - } - else - { - handler( new Exception( 'message' ) ); - } + handler( result ); } ); } - static function _loadString( failure : Bool ) : IAsyncCallback + static function _loadString( result : Result ) : IAsyncCallback { return AsyncCallback.get ( function ( handler : Handler ) { - if ( !failure ) - { - handler( 'test' ); - } - else - { - handler( new Exception( 'message' ) ); - } + handler( result ); } ); } From 9f0a2ff451d634960c9563b2323dff7745664da4 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Fri, 10 Mar 2017 13:49:33 +0100 Subject: [PATCH 2/9] IAsyncCallback getters added (isCompleted, isFailed, isCancelled) --- src/hex/control/async/AsyncCallback.hx | 47 ++++- src/hex/control/async/IAsyncCallback.hx | 4 + test/hex/control/AsyncCallbackTest.hx | 252 ++++++++++++++++-------- 3 files changed, 224 insertions(+), 79 deletions(-) diff --git a/src/hex/control/async/AsyncCallback.hx b/src/hex/control/async/AsyncCallback.hx index d2de9b9..78605ec 100644 --- a/src/hex/control/async/AsyncCallback.hx +++ b/src/hex/control/async/AsyncCallback.hx @@ -1,8 +1,11 @@ package hex.control.async; -import haxe.ds.StringMap; +#if macro import haxe.macro.Context; import haxe.macro.Expr; +#end + +import haxe.ds.StringMap; import hex.error.Exception; import hex.error.IllegalStateException; import hex.error.PrivateConstructorException; @@ -42,6 +45,48 @@ class AsyncCallback implements IAsyncCallback return AsyncCallbackUtil.whenComplete( ethis, clazz ); } + @:final + public var isCompleted( get, null ) : Bool; + public function get_isCompleted() : Bool + { + switch( this._result ) + { + case Result.DONE( result ): + return true; + + case _: + return false; + } + } + + @:final + public var isFailed( get, null ) : Bool; + public function get_isFailed() : Bool + { + switch( this._result ) + { + case Result.FAILED( error ): + return true; + + case _: + return false; + } + } + + @:final + public var isCancelled( get, null ) : Bool; + public function get_isCancelled() : Bool + { + switch( this._result ) + { + case Result.CANCELLED: + return true; + + case _: + return false; + } + } + public function onComplete( onComplete : Callback ) : AsyncCallback { switch( this._result ) diff --git a/src/hex/control/async/IAsyncCallback.hx b/src/hex/control/async/IAsyncCallback.hx index dbf6d5a..6eec77f 100644 --- a/src/hex/control/async/IAsyncCallback.hx +++ b/src/hex/control/async/IAsyncCallback.hx @@ -11,4 +11,8 @@ interface IAsyncCallback function onComplete( onComplete : Callback ) : IAsyncCallback; function onFail( onFail : Exception->Void ) : IAsyncCallback; function onCancel( onCancel : Void->Void ) : IAsyncCallback; + + var isCompleted( get, null ) : Bool; + var isFailed( get, null ) : Bool; + var isCancelled( get, null ) : Bool; } \ No newline at end of file diff --git a/test/hex/control/AsyncCallbackTest.hx b/test/hex/control/AsyncCallbackTest.hx index 4a5d071..667d7aa 100644 --- a/test/hex/control/AsyncCallbackTest.hx +++ b/test/hex/control/AsyncCallbackTest.hx @@ -25,7 +25,7 @@ class AsyncCallbackTest var cancel = false; //test completion - _loadString( Result.DONE( 'test' ) ) + var acb = _loadString( Result.DONE( 'test' ) ) .onComplete( function(r) result = r ) .onFail( function(e) error = e ) .onCancel( function() cancel = true ); @@ -34,12 +34,16 @@ class AsyncCallbackTest Assert.isNull( error ); Assert.isFalse( cancel ); + Assert.isTrue( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); + Assert.isFalse( acb.isCancelled ); + //test failure result = null; error = null; cancel = false; - _loadString( Result.FAILED( new Exception( 'message' ) ) ) + acb = _loadString( Result.FAILED( new Exception( 'message' ) ) ) .onComplete( function(r) result = r ) .onFail( function(e) error = e ) .onCancel( function() cancel = true ); @@ -49,12 +53,16 @@ class AsyncCallbackTest Assert.isNull( result ); Assert.isFalse( cancel ); + Assert.isTrue( acb.isFailed ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isCancelled ); + //test cancel result = null; error = null; cancel = false; - _loadString( Result.CANCELLED ) + acb = _loadString( Result.CANCELLED ) .onComplete( function(r) result = r ) .onFail( function(e) error = e ) .onCancel( function() cancel = true ); @@ -62,6 +70,10 @@ class AsyncCallbackTest Assert.isTrue( cancel ); Assert.isNull( result ); Assert.isNull( error ); + + Assert.isTrue( acb.isCancelled ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); } @Test( 'Test without argument result' ) @@ -72,7 +84,7 @@ class AsyncCallbackTest var cancel = false; //test completion - _load( Result.DONE( Nothing ) ) + var acb = _load( Result.DONE( Nothing ) ) .onComplete( function() result = Nothing ) .onFail( function(e) error = e ) .onCancel( function() cancel = true ); @@ -81,12 +93,16 @@ class AsyncCallbackTest Assert.isNull( error ); Assert.isFalse( cancel ); + Assert.isTrue( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); + Assert.isFalse( acb.isCancelled ); + //test failure result = null; error = null; cancel = false; - _load( Result.FAILED( new Exception( 'message' ) ) ) + acb = _load( Result.FAILED( new Exception( 'message' ) ) ) .onComplete( function(r) result = r ) .onFail( function(e) error = e ) .onCancel( function() cancel = true ); @@ -96,12 +112,16 @@ class AsyncCallbackTest Assert.isNull( result ); Assert.isFalse( cancel ); + Assert.isTrue( acb.isFailed ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isCancelled ); + //test cancel result = null; error = null; cancel = false; - _load( Result.CANCELLED ) + acb = _load( Result.CANCELLED ) .onComplete( function(r) result = r ) .onFail( function(e) error = e ) .onCancel( function() cancel = true ); @@ -109,23 +129,31 @@ class AsyncCallbackTest Assert.isTrue( cancel ); Assert.isNull( result ); Assert.isNull( error ); + + Assert.isTrue( acb.isCancelled ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); } @Test( 'Test completion twice' ) public function testCompletionTwice() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( Nothing ); - handler( Nothing ); - } - ); + handler( Nothing ); + handler( Nothing ); } catch ( e : IllegalStateException ) { @@ -133,23 +161,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); + Assert.isFalse( acb.isCancelled ); } @Test( 'Test failure twice' ) public function testFailureTwice() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( new Exception( 'message' ) ); - handler( new Exception( 'message' ) ); - } - ); + handler( new Exception( 'message' ) ); + handler( new Exception( 'message' ) ); } catch ( e : IllegalStateException ) { @@ -157,23 +193,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isFailed ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isCancelled ); } @Test( 'Test cancel twice' ) public function tesCancelTwice() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( Result.CANCELLED ); - handler( Result.CANCELLED ); - } - ); + handler( Result.CANCELLED ); + handler( Result.CANCELLED ); } catch ( e : IllegalStateException ) { @@ -181,23 +225,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isCancelled ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); } @Test( 'Test completion and failure at the same time' ) public function testCompletionAndFailureAtTheSameTime() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( Nothing ); - handler( new Exception( 'message' ) ); - } - ); + handler( Nothing ); + handler( new Exception( 'message' ) ); } catch ( e : IllegalStateException ) { @@ -205,23 +257,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); + Assert.isFalse( acb.isCancelled ); } @Test( 'Test failure and completion at the same time' ) public function testFailureAndCompletionAtTheSameTime() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( new Exception( 'message' ) ); - handler( Nothing ); - } - ); + handler( new Exception( 'message' ) ); + handler( Nothing ); } catch ( e : IllegalStateException ) { @@ -229,23 +289,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isFailed ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isCancelled ); } @Test( 'Test completion and cancel at the same time' ) public function testCompletionAndCancelAtTheSameTime() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( Nothing ); - handler( Result.CANCELLED ); - } - ); + handler( Nothing ); + handler( Result.CANCELLED ); } catch ( e : IllegalStateException ) { @@ -253,23 +321,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); + Assert.isFalse( acb.isCancelled ); } @Test( 'Test completion and cancel at the same time' ) public function testCancelAndCompletionAtTheSameTime() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( Result.CANCELLED ); - handler( Nothing ); - } - ); + handler( Result.CANCELLED ); + handler( Nothing ); } catch ( e : IllegalStateException ) { @@ -277,23 +353,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isCancelled ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); } @Test( 'Test failure and cancel at the same time' ) public function testFailureAndCancelAtTheSameTime() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( new Exception( 'message' ) ); - handler( Result.CANCELLED ); - } - ); + handler( new Exception( 'message' ) ); + handler( Result.CANCELLED ); } catch ( e : IllegalStateException ) { @@ -301,23 +385,31 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isFailed ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isCancelled ); } @Test( 'Test cancel and failure at the same time' ) public function testCancelAndFailureAtTheSameTime() : Void { var error : IllegalStateException = null; + var acb : AsyncCallback = null; + var handler : Handler = null; + + acb = AsyncCallback.get + ( + function ( h : Handler ) + { + handler = h; + } + ); try { - AsyncCallback.get - ( - function ( handler : Handler ) - { - handler( Result.CANCELLED ); - handler( new Exception( 'message' ) ); - } - ); + handler( Result.CANCELLED ); + handler( new Exception( 'message' ) ); } catch ( e : IllegalStateException ) { @@ -325,6 +417,10 @@ class AsyncCallbackTest } Assert.isInstanceOf( error, IllegalStateException ); + + Assert.isTrue( acb.isCancelled ); + Assert.isFalse( acb.isCompleted ); + Assert.isFalse( acb.isFailed ); } @Test( "test simple lambda chaining" ) From d20733f6969e9ef3c095db2970601e60300fd427 Mon Sep 17 00:00:00 2001 From: Laurent Deketelaere Date: Mon, 13 Mar 2017 14:42:13 +0100 Subject: [PATCH 3/9] purge cachedMethodCalls progressively in Dispatch ( close DoclerLabs/hexMachina#221 ) --- src/hex/event/Dispatcher.hx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hex/event/Dispatcher.hx b/src/hex/event/Dispatcher.hx index e072c97..62c35ed 100644 --- a/src/hex/event/Dispatcher.hx +++ b/src/hex/event/Dispatcher.hx @@ -323,14 +323,13 @@ class Dispatcher implements IDispatcher if ( isSealed != this._isSealed ) { this._isSealed = isSealed; - if ( !this._isSealed && this._cachedMethodCalls.length > 0 ) + if ( !this._isSealed ) { - for ( cachedMethodCall in this._cachedMethodCalls ) + while ( this._cachedMethodCalls.length > 0 ) { - cachedMethodCall(); + var func = this._cachedMethodCalls.shift(); + func(); } - - this._cachedMethodCalls = []; } } } From 0b0c70cab1afa2c79e40d797873bcc4677750374 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 15 Mar 2017 14:49:16 +0100 Subject: [PATCH 4/9] IAsyncCallback.isWaiting accessor added --- src/hex/control/async/AsyncCallback.hx | 14 ++++++++++++++ src/hex/control/async/IAsyncCallback.hx | 1 + 2 files changed, 15 insertions(+) diff --git a/src/hex/control/async/AsyncCallback.hx b/src/hex/control/async/AsyncCallback.hx index 78605ec..1bc02a1 100644 --- a/src/hex/control/async/AsyncCallback.hx +++ b/src/hex/control/async/AsyncCallback.hx @@ -45,6 +45,20 @@ class AsyncCallback implements IAsyncCallback return AsyncCallbackUtil.whenComplete( ethis, clazz ); } + @:final + public var isWaiting( get, null ) : Bool; + public function get_isWaiting() : Bool + { + switch( this._result ) + { + case Result.WAITING: + return true; + + case _: + return false; + } + } + @:final public var isCompleted( get, null ) : Bool; public function get_isCompleted() : Bool diff --git a/src/hex/control/async/IAsyncCallback.hx b/src/hex/control/async/IAsyncCallback.hx index 6eec77f..fd20957 100644 --- a/src/hex/control/async/IAsyncCallback.hx +++ b/src/hex/control/async/IAsyncCallback.hx @@ -12,6 +12,7 @@ interface IAsyncCallback function onFail( onFail : Exception->Void ) : IAsyncCallback; function onCancel( onCancel : Void->Void ) : IAsyncCallback; + var isWaiting( get, null ) : Bool; var isCompleted( get, null ) : Bool; var isFailed( get, null ) : Bool; var isCancelled( get, null ) : Bool; From 33b771d421fd5383d099d87650e5bd4454274704 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 16 Mar 2017 14:41:33 +0100 Subject: [PATCH 5/9] IAsyncCallback renamed Expect --- src/hex/control/async/AsyncCallback.hx | 2 +- src/hex/control/async/Expect.hx | 19 +++++++++++++++++++ src/hex/control/async/IAsyncCallback.hx | 19 ------------------- test/hex/control/AsyncCallbackTest.hx | 6 +++--- 4 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 src/hex/control/async/Expect.hx delete mode 100644 src/hex/control/async/IAsyncCallback.hx diff --git a/src/hex/control/async/AsyncCallback.hx b/src/hex/control/async/AsyncCallback.hx index 1bc02a1..fe60bcc 100644 --- a/src/hex/control/async/AsyncCallback.hx +++ b/src/hex/control/async/AsyncCallback.hx @@ -14,7 +14,7 @@ import hex.error.PrivateConstructorException; * ... * @author Francis Bourre */ -class AsyncCallback implements IAsyncCallback +class AsyncCallback implements Expect { static var _map : Map, Bool> = new Map(); diff --git a/src/hex/control/async/Expect.hx b/src/hex/control/async/Expect.hx new file mode 100644 index 0000000..20ecc74 --- /dev/null +++ b/src/hex/control/async/Expect.hx @@ -0,0 +1,19 @@ +package hex.control.async; + +import hex.error.Exception; + +/** + * @author Francis Bourre + */ + +interface Expect +{ + function onComplete( onComplete : Callback ) : Expect; + function onFail( onFail : Exception->Void ) : Expect; + function onCancel( onCancel : Void->Void ) : Expect; + + var isWaiting( get, null ) : Bool; + var isCompleted( get, null ) : Bool; + var isFailed( get, null ) : Bool; + var isCancelled( get, null ) : Bool; +} \ No newline at end of file diff --git a/src/hex/control/async/IAsyncCallback.hx b/src/hex/control/async/IAsyncCallback.hx deleted file mode 100644 index fd20957..0000000 --- a/src/hex/control/async/IAsyncCallback.hx +++ /dev/null @@ -1,19 +0,0 @@ -package hex.control.async; - -import hex.error.Exception; - -/** - * @author Francis Bourre - */ - -interface IAsyncCallback -{ - function onComplete( onComplete : Callback ) : IAsyncCallback; - function onFail( onFail : Exception->Void ) : IAsyncCallback; - function onCancel( onCancel : Void->Void ) : IAsyncCallback; - - var isWaiting( get, null ) : Bool; - var isCompleted( get, null ) : Bool; - var isFailed( get, null ) : Bool; - var isCancelled( get, null ) : Bool; -} \ No newline at end of file diff --git a/test/hex/control/AsyncCallbackTest.hx b/test/hex/control/AsyncCallbackTest.hx index 667d7aa..4d0ff55 100644 --- a/test/hex/control/AsyncCallbackTest.hx +++ b/test/hex/control/AsyncCallbackTest.hx @@ -2,7 +2,7 @@ package hex.control; import hex.control.async.AsyncCallback; import hex.control.async.Handler; -import hex.control.async.IAsyncCallback; +import hex.control.async.Expect; import hex.control.async.Nothing; import hex.error.Exception; import hex.error.IllegalArgumentException; @@ -504,7 +504,7 @@ class AsyncCallbackTest , collection, "collection content should be the same" ); } - static function _load( result : Result ) : IAsyncCallback + static function _load( result : Result ) : Expect { return AsyncCallback.get ( @@ -515,7 +515,7 @@ class AsyncCallbackTest ); } - static function _loadString( result : Result ) : IAsyncCallback + static function _loadString( result : Result ) : Expect { return AsyncCallback.get ( From f881eab4a7b1bb2829bbbc9b45990fa65e898e7e Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 16 Mar 2017 15:48:30 +0100 Subject: [PATCH 6/9] Type params improved in injection API --- src/hex/di/IDependencyInjector.hx | 4 ++-- src/hex/di/provider/IDependencyProvider.hx | 4 ++-- test/hex/control/payload/PayloadUtilTest.hx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hex/di/IDependencyInjector.hx b/src/hex/di/IDependencyInjector.hx index 87a1a8c..5924be6 100644 --- a/src/hex/di/IDependencyInjector.hx +++ b/src/hex/di/IDependencyInjector.hx @@ -13,11 +13,11 @@ interface IDependencyInjector extends IBasicInjector function injectInto( target : Dynamic ) : Void; - function destroyInstance( instance : Dynamic ) : Void; + function destroyInstance( instance : T ) : Void; function addListener( listener: IInjectorListener ) : Bool; function removeListener( listener: IInjectorListener ) : Bool; - function getProvider( className : String, name : String = '' ) : IDependencyProvider; + function getProvider( className : String, name : String = '' ) : IDependencyProvider; } \ No newline at end of file diff --git a/src/hex/di/provider/IDependencyProvider.hx b/src/hex/di/provider/IDependencyProvider.hx index 6a8243f..35041a2 100644 --- a/src/hex/di/provider/IDependencyProvider.hx +++ b/src/hex/di/provider/IDependencyProvider.hx @@ -4,8 +4,8 @@ package hex.di.provider; * ... * @author Francis Bourre */ -interface IDependencyProvider +interface IDependencyProvider { - function getResult( injector : IDependencyInjector ) : Dynamic; + function getResult( injector : IDependencyInjector ) : T; function destroy() : Void; } diff --git a/test/hex/control/payload/PayloadUtilTest.hx b/test/hex/control/payload/PayloadUtilTest.hx index e623786..e09c0ed 100644 --- a/test/hex/control/payload/PayloadUtilTest.hx +++ b/test/hex/control/payload/PayloadUtilTest.hx @@ -208,7 +208,7 @@ private class MockDependencyInjector implements IDependencyInjector return false; } - public function getProvider( className : String, name : String = '' ) : IDependencyProvider + public function getProvider( className : String, name : String = '' ) : IDependencyProvider { return null; } From 7a755bc4390c6c45820842c9408c9c42fd7ff5e8 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 16 Mar 2017 15:55:39 +0100 Subject: [PATCH 7/9] fix for previous commit --- test/hex/MockDependencyInjector.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hex/MockDependencyInjector.hx b/test/hex/MockDependencyInjector.hx index e7d3373..fd0e594 100644 --- a/test/hex/MockDependencyInjector.hx +++ b/test/hex/MockDependencyInjector.hx @@ -90,7 +90,7 @@ class MockDependencyInjector implements IDependencyInjector return false; } - public function getProvider( className : String, name : String = '' ) : IDependencyProvider + public function getProvider( className : String, name : String = '' ) : IDependencyProvider { return null; } From 6dd66a610426717ec66bb9da0d99a78e86e59f6f Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Fri, 17 Mar 2017 07:55:18 +0100 Subject: [PATCH 8/9] Di interfaces formatting --- src/hex/di/IBasicInjector.hx | 8 ++++---- src/hex/di/IDependencyInjector.hx | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hex/di/IBasicInjector.hx b/src/hex/di/IBasicInjector.hx index e7e6da1..0f72af0 100644 --- a/src/hex/di/IBasicInjector.hx +++ b/src/hex/di/IBasicInjector.hx @@ -7,9 +7,9 @@ interface IBasicInjector { function mapToValue( clazz : Class, value : T, ?name : String = '' ) : Void; - function mapToType( clazz : Class, type : Class, name:String = '' ) : Void; + function mapToType( clazz : Class, type : Class, name : String = '' ) : Void; - function mapToSingleton( clazz : Class, type : Class, name:String = '' ) : Void; + function mapToSingleton( clazz : Class, type : Class, name : String = '' ) : Void; function getInstance( type : Class, name : String = '' ) : T; @@ -27,7 +27,7 @@ interface IBasicInjector function mapClassNameToValue( className : String, value : T, ?name : String = '' ) : Void; - function mapClassNameToType( className : String, type : Class, name:String = '' ) : Void; + function mapClassNameToType( className : String, type : Class, name : String = '' ) : Void; - function mapClassNameToSingleton( className : String, type : Class, name:String = '' ) : Void; + function mapClassNameToSingleton( className : String, type : Class, name : String = '' ) : Void; } \ No newline at end of file diff --git a/src/hex/di/IDependencyInjector.hx b/src/hex/di/IDependencyInjector.hx index 5924be6..f3cdf06 100644 --- a/src/hex/di/IDependencyInjector.hx +++ b/src/hex/di/IDependencyInjector.hx @@ -7,11 +7,11 @@ import hex.di.provider.IDependencyProvider; */ interface IDependencyInjector extends IBasicInjector { - function hasDirectMapping( type : Class, name:String = '' ) : Bool; + function hasDirectMapping( type : Class, name : String = '' ) : Bool; - function satisfies( type : Class, name : String = '' ) : Bool; + function satisfies( type : Class, name : String = '' ) : Bool; - function injectInto( target : Dynamic ) : Void; + function injectInto( target : T ) : Void; function destroyInstance( instance : T ) : Void; From 6251ec2b6f0adf0dfd77595d0292ff985c32caa9 Mon Sep 17 00:00:00 2001 From: Laurent Deketelaere Date: Tue, 21 Mar 2017 11:16:10 +0100 Subject: [PATCH 9/9] DoclerLabs/hexMachina#222 Drop haxe 3.2.1 support --- .travis.yml | 5 ++--- src/hex/model/IModelDispatcher.hx | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d2883d..18b8da2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ language: haxe # haxe versions : http://haxe.org/website-content/downloads/versions.json haxe: - - "3.2.1" - "3.4.0" - development @@ -46,10 +45,10 @@ install: - haxe flash/install.hxml script: - - if [ $TRAVIS_HAXE_VERSION != "3.2.1" ]; then haxe build-php.hxml && php bin; fi + - haxe build-php.hxml && php bin/index.php - haxe build-neko.hxml && neko bin/MainTest.n - haxe build-js.hxml && node bin/MainTest.js - - if [ $TRAVIS_HAXE_VERSION != "3.2.1" ]; then haxe build-flash.hxml -D fdb && haxe flash/run.hxml bin/MainTest.swf; fi + - haxe build-flash.hxml -D fdb && haxe flash/run.hxml bin/MainTest.swf notifications: email: diff --git a/src/hex/model/IModelDispatcher.hx b/src/hex/model/IModelDispatcher.hx index 2adc487..d41545b 100644 --- a/src/hex/model/IModelDispatcher.hx +++ b/src/hex/model/IModelDispatcher.hx @@ -5,10 +5,6 @@ package hex.model; */ typedef IModelDispatcher = { - #if ( haxe_ver < "3.3" ) - public function new() : Void; - #end - public function addListener( listener : ListenerType ) : Bool; public function removeListener( listener : ListenerType ) : Bool;