Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ export default class PushReceiver extends Emitter<ClientEvents> {

#clearReady() {
if (!this.#ready.isResolved) {
// Attach a catch handler to prevent unhandled rejection warning
this.#ready.promise.catch(() => {})
this.#ready.reject(new Error('Client destroyed'))
Comment on lines 197 to 200
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!this.#ready.isResolved) is not doing what it suggests: defer() currently returns isResolved as a snapshot boolean, so it never updates when resolve/reject are called (see src/utils/defer.ts). As a result, #clearReady() will always enter this block and attempt to reject, even after the promise was already settled. Consider changing defer() to expose a live flag (e.g., a getter) or updating this check so it accurately reflects the promise state.

Suggested change
if (!this.#ready.isResolved) {
// Attach a catch handler to prevent unhandled rejection warning
this.#ready.promise.catch(() => {})
this.#ready.reject(new Error('Client destroyed'))
// Attach a catch handler to prevent unhandled rejection warning
this.#ready.promise.catch(() => {})
// Safely attempt to reject the current ready promise, even if it may
// already be settled. Wrap in try/catch in case the underlying
// implementation throws when rejecting a settled promise.
try {
this.#ready.reject(new Error('Client destroyed'))
} catch {
// Ignore errors from rejecting an already-settled promise

Copilot uses AI. Check for mistakes.
}

Expand Down