Fix AsyncEvent callback triggering.

Before this, two concurrent postCall() and completeIntent() calls might
cause the callback to be called more than once.
This commit is contained in:
minecraftshamrock 2015-03-30 18:40:34 +02:00 committed by md_5
parent 70564d9f44
commit 9cf57ca929

View File

@ -33,11 +33,11 @@ public class AsyncEvent<T> extends Event
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void postCall() public void postCall()
{ {
fired.set( true );
if ( latch.get() == 0 ) if ( latch.get() == 0 )
{ {
done.done( (T) this, null ); done.done( (T) this, null );
} }
fired.set( true );
} }
/** /**
@ -67,9 +67,14 @@ public class AsyncEvent<T> extends Event
{ {
Preconditions.checkState( intents.contains( plugin ), "Plugin %s has not registered intent for event %s", plugin, this ); Preconditions.checkState( intents.contains( plugin ), "Plugin %s has not registered intent for event %s", plugin, this );
intents.remove( plugin ); intents.remove( plugin );
if ( latch.decrementAndGet() == 0 && fired.get() ) if ( fired.get() )
{
if ( latch.decrementAndGet() == 0 )
{ {
done.done( (T) this, null ); done.done( (T) this, null );
} }
} else {
latch.decrementAndGet();
}
} }
} }