-
Notifications
You must be signed in to change notification settings - Fork 12
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
handle error events on xkeys that can be emitted during the init process before the instance is exposed for listener registration #113
Conversation
…ess before the instance is exposed for listener registration
packages/webhid/src/methods.ts
Outdated
.finally(() => (alreadyRejected = true)) | ||
} | ||
// Handle all error events until the instance is returned | ||
xkeys.on('error', xkeysStopgapErrorHandler) |
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.
we don't use once
intentionally. Until we have resolved back the instance to the caller, we are responsible to keep catching errors that may be emitted.
Implementation could be revised with the addition of a |
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.
Thanks for this PR! I agree, this should handle the edge case where an error event is emitted during initialization.
Note to self: When merging this, add a equivalent handling to setupXKeysPanel
in the node-package.
packages/webhid/src/methods.ts
Outdated
return | ||
} | ||
deviceWrap.close() | ||
.then(() => 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.
Minor note: is there a reason the reject()
has no argument here? Should we reject(e)
?
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.
This is for the path where deviceWrap.close()
promise resolves, where it should resolve to a void promise, but still I want to avoid forwarding whatever value it resolves to as the rejected value of the enclosing (returned) promise in case the API of that method changes.
I added an implementation for node in #114. I also simplified the implementation here and there to not handle the cleanup inside the promise executor, and instead rely on the existing catch clause which execution will break out to if the promise rejects. |
packages/webhid/src/methods.ts
Outdated
.close() | ||
.then(() => reject()) | ||
.catch(reject) | ||
.finally(() => (alreadyRejected = true)) |
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.
doing this in the finally
(old implementation) was not semantically coherent since the flag only makes sense when the promise rejects, not when it resolves (same applies below). So changed this.
Fixes #112 (implements the first approach discussed)