Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Oct 25, 2024
1 parent 6a6c9e6 commit 1913a6f
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class TestVisDynamicInstrumentation {
return [
snapshotId,
new Promise(resolve => {
const id = randomUUID()
probeIdToResolvePromise.set(id, resolve)
const probeId = randomUUID()
probeIdToResolvePromise.set(probeId, resolve)
this.worker.postMessage({
snapshotId,
probe: { id, file, line }
probe: { id: probeId, file, line }
})
})
]
Expand All @@ -49,11 +49,12 @@ class TestVisDynamicInstrumentation {
// Allow the parent to exit even if the worker is still running
this.worker.unref()

this.worker.on('message', ({ id, probe, state, stack, snapshot }) => {
const resolveSnapshot = probeIdToResolvePromise.get(id)
if (resolveSnapshot) {
resolveSnapshot({ probe, state, stack, snapshot })
probeIdToResolvePromise.delete(id)
this.worker.on('message', ({ snapshot }) => {
const { probe: { id: probeId } } = snapshot
const resolve = probeIdToResolvePromise.get(probeId)
if (resolve) {
resolve({ snapshot })
probeIdToResolvePromise.delete(probeId)
}
}).unref() // We also need to unref this message handler
}
Expand Down

0 comments on commit 1913a6f

Please sign in to comment.