Skip to content

Commit

Permalink
Fix memory leak in waitDevice method
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffone17 committed Sep 17, 2024
1 parent ece3d3e commit bd294ed
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ class Adapter {
cancellable.push(() => clearTimeout(handler))
})

const device = await Promise.race([discoveryHandler, timeoutHandler])

for (const cancel of cancellable) {
cancel()
try {
const device = await Promise.race([discoveryHandler, timeoutHandler])
return device
} finally {
for (const cancel of cancellable) {
cancel()
}
}
return device
}

/**
Expand Down

0 comments on commit bd294ed

Please sign in to comment.