Skip to content

Commit

Permalink
test: fix failing test on node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlup committed Dec 18, 2023
1 parent 749b00d commit 80c0c57
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ class Sampler extends EventEmitter {
this.start()
}
if (instances.hasSubscribers) {
process.nextTick(() => instances.publish(this))
process.nextTick(() => {
try {
// On Node 18 the `hasSubscribers` check is not enough so this call fails
// with an uncaught exception if there are no subscribers.
instances.publish(this)
} catch (_) {}
})
}
}

Expand Down Expand Up @@ -121,7 +127,11 @@ class Sampler extends EventEmitter {
this.emit('sample')
this[kReset]()
if (samples.hasSubscribers) {
samples.publish(this)
try {
// On Node 18 the `hasSubscribers` check is not enough so this call fails
// with an uncaught exception if there are no subscribers.
samples.publish(this)
} catch (_) {}
}
}

Expand Down

0 comments on commit 80c0c57

Please sign in to comment.