Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Fixes to state guarding logic around immediate notifications in Defer…
Browse files Browse the repository at this point in the history
…red.

Modified state checks to use existing convenience accessors for brevity and clarity.
Updated SWC.
  • Loading branch information
John Yanarella committed Sep 4, 2011
1 parent a4d6adc commit c921b0e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Binary file modified bin/flex-extensions.swc
Binary file not shown.
44 changes: 23 additions & 21 deletions src/com/codecatalyst/util/promise/Deferred.as
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,18 @@ package com.codecatalyst.util.promise
*/
public function always( alwaysCallback:Function ):Deferred
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
if ( alwaysCallback != null )
alwaysCallbacks.push( alwaysCallback );
}
else
else if ( succeeded )
{
switch ( state )
{
case Deferred.SUCCEEDED_STATE:
notify( [ alwaysCallback ], result );
break;

case Deferred.FAILED_STATE:
notify( [ alwaysCallback ], error );
break;
}
notify( [ alwaysCallback ], result );
}
else if ( failed )
{
notify( [ alwaysCallback ], error );
}

return this;
Expand Down Expand Up @@ -295,7 +290,7 @@ package com.codecatalyst.util.promise
*/
public function onProgress( progressCallback:Function ):Deferred
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
if ( progressCallback != null )
progressCallbacks.push( progressCallback );
Expand All @@ -312,12 +307,12 @@ package com.codecatalyst.util.promise
*/
public function onResult( resultCallback:Function ):Deferred
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
if ( resultCallback != null )
resultCallbacks.push( resultCallback );
}
else
else if ( succeeded )
{
notify( [ resultCallback ], result );
}
Expand All @@ -330,8 +325,15 @@ package com.codecatalyst.util.promise
*/
public function onError( errorCallback:Function ):Deferred
{
if ( errorCallback != null )
errorCallbacks.push( errorCallback );
if ( pending )
{
if ( errorCallback != null )
errorCallbacks.push( errorCallback );
}
else if ( failed )
{
notify( [ errorCallback ], error );
}

return this;
}
Expand All @@ -341,7 +343,7 @@ package com.codecatalyst.util.promise
*/
public function resolve( result:* ):void
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
this.result = result;
setState( Deferred.SUCCEEDED_STATE );
Expand All @@ -356,7 +358,7 @@ package com.codecatalyst.util.promise
*/
public function reject( error:* ):void
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
this.error = error;
setState( Deferred.FAILED_STATE );
Expand All @@ -371,7 +373,7 @@ package com.codecatalyst.util.promise
*/
public function update( progress:* ):void
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
this.progress = progress;

Expand All @@ -384,7 +386,7 @@ package com.codecatalyst.util.promise
*/
public function cancel():void
{
if ( state == Deferred.PENDING_STATE )
if ( pending )
{
setState( Deferred.CANCELLED_STATE );

Expand Down

0 comments on commit c921b0e

Please sign in to comment.