Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/114'
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Dec 5, 2024
2 parents 193eb78 + 454ac00 commit 33305e7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/node/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,34 @@ export async function setupXkeysPanel(
// Wait for the device to initialize:
await xkeys.init()

let alreadyRejected = false
await new Promise<void>((resolve, reject) => {
const markRejected = (e: unknown) => {
reject(e)
alreadyRejected = true
}
const xkeysStopgapErrorHandler = (e: unknown) => {
if (alreadyRejected) {
console.error(`Xkeys: Error emitted after setup already rejected:`, e)
return
}

markRejected(e)
}

// Handle all error events until the instance is returned
xkeys.on('error', xkeysStopgapErrorHandler)

// Wait for the device to initialize:
xkeys
.init()
.then(() => {
resolve()
xkeys.removeListener('error', xkeysStopgapErrorHandler)
})
.catch(markRejected)
})

return xkeys
} catch (e) {
if (device) await device.close().catch(() => null) // Suppress error
Expand Down

0 comments on commit 33305e7

Please sign in to comment.