-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion to simplify prevention of dangling Promise on destroy #286
base: fix/internal-listeners
Are you sure you want to change the base?
Conversation
331159a
to
f3fe246
Compare
The `fix/internal-listeners` branch has a number of changes intended to ensure we don't have a dangling unresolved Promise when the block tracker is destroyed. This solution involved adding an additional listener to capture errors, and it involved not removing internal listeners when `destroy` is called. This required changes to some logging in `_updateAndQueue` as well. This commit is an alternative solution that avoids the use of internal listeners, thus avoiding much of the complexity in the previous solution. Instead an internal deferred Promise is used. This also might be slightly more efficient when `getLatestBlock` is called repeatedly, as we can reuse the same listener rather than creating a new one each time.
f3fe246
to
3435c0a
Compare
@@ -118,37 +117,23 @@ export class PollingBlockTracker | |||
// return if available | |||
if (this._currentBlock) { | |||
return this._currentBlock; | |||
} else if (this.#pendingLatestBlock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch here. I was thinking of also using a deferred promise and keeping it in a private field, but it seemed that calling getLatestBlock
multiple times without waiting would overwrite that field. This is a good solution.
}); | ||
// return newly set current block | ||
return latestBlock; | ||
this.#pendingLatestBlock = { promise, reject }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering, if we are making this promise available to the rest of the class, would it make sense to also resolve it through this class variable and get rid of the internal listener altogether?
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, yeah maybe so, good idea
The
fix/internal-listeners
branch has a number of changes intended to ensure we don't have a dangling unresolved Promise when the block tracker is destroyed. This solution involved adding an additional listener to capture errors, and it involved not removing internal listeners whendestroy
is called. This required changes to some logging in_updateAndQueue
as well.This commit is an alternative solution that avoids the use of internal listeners, thus avoiding much of the complexity in the previous solution. Instead an internal deferred Promise is used. This also might be slightly more efficient when
getLatestBlock
is called repeatedly, as we can reuse the same listener rather than creating a new one each time.