1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-14 22:43:27 +00:00

Updated so if promise is already resolved/rejected when 'then' is called, the event is unhooked.

This commit is contained in:
Bryan Roe
2021-03-23 11:22:29 -07:00
parent b27ebd6c4b
commit bc5feacb04
2 changed files with 8 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -93,7 +93,7 @@ function Promise(promiseFunc)
{
this.completedArgs = [];
});
this._internal.on('newListener', (function (eventName, eventCallback)
this._internal.on('newListener2', (function (eventName, eventCallback)
{
//console.log('newListener', eventName, 'errors/' + this.errors + ' completed/' + this.completed);
var r = null;
@@ -105,6 +105,8 @@ function Promise(promiseFunc)
{
this.emit_returnValue('resolved', r);
}
this.removeAllListeners('resolved');
this.removeAllListeners('rejected');
}
if (eventName == 'rejected' && (eventCallback.internal == null || eventCallback.internal == false))
@@ -126,6 +128,8 @@ function Promise(promiseFunc)
if (eventName == 'rejected' && this.errors && this.completed)
{
eventCallback.apply(this, this.completedArgs);
this.removeAllListeners('resolved');
this.removeAllListeners('rejected');
}
if (eventName == 'settled' && this.completed)
{