@@ -301,6 +301,11 @@ namespace promises.internal
301
301
' unregister any observers once the promise is completed
302
302
promises .internal .unobserveFieldScoped (originalPromise , promises .internal .PromiseField .promiseState )
303
303
promiseStorage = promises .internal .getPromiseStorage (originalPromise )
304
+ ' Delete the storage for this promise since we are going to handled all of the current listeners.
305
+ ' Any new listeners created as a result of the logic in the callbacks will
306
+ ' register a new instance of the promise storage item. If a new storage item is created
307
+ ' we will notify the new listeners when we are done with the current ones.
308
+ promises .internal .clearPromiseStorage (originalPromise )
304
309
305
310
promiseState = originalPromise .promiseState
306
311
promiseResult = originalPromise .promiseResult
@@ -326,11 +331,22 @@ namespace promises.internal
326
331
'TODO giant memory leak. if you see this, delete it immediately!
327
332
m .__promises__debug .push (promiseStorage )
328
333
#end if
329
- 'delete the storage for this promise since we've handled all of the listeners
330
- promises .internal .clearPromiseStorage (originalPromise )
334
+
335
+ if promises .internal .hasStorage (originalPromise ) then
336
+ ' There were listeners added as a result of some of the callback notifications
337
+ ' Re-trigger the notification process for the new listeners
338
+ promises .internal .delay (sub (event as object )
339
+ promises .internal .notifyListeners (event )
340
+ end sub , event )
341
+ end if
331
342
end if
332
343
end sub
333
344
345
+ ' Used to check if there is a storage item of listeners for the supplied promise
346
+ function hasStorage (promise as dynamic ) as boolean
347
+ return m .doesExist ("__promises__" + promise .id )
348
+ end function
349
+
334
350
' We use an internal value to represent unset. Check if the parameter is that value
335
351
function isSet (value as dynamic ) as boolean
336
352
return not (promises .internal .isNonEmptyString (value ) and value = "__INVALID__" )
0 commit comments