Skip to content

Commit

Permalink
use MessagePort instead of setInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Jan 21, 2023
1 parent adbc3d0 commit a71cc25
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/runtime/src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,26 @@ class CleanupQueue {
}

class NodejsWaitingRequestCounter {
private timer: any = undefined
private count: number = 0
private readonly refHandle: { ref: () => void; unref: () => void }
private count: number

constructor () {
this.refHandle = new MessageChannel().port1 as unknown as import('worker_threads').MessagePort
this.refHandle.unref()

This comment has been minimized.

Copy link
@RReverser

RReverser Jan 21, 2023

Contributor

AFAIK it's created in unref state already.

this.count = 0
}

public increase (): void {
if (this.count === 0) {
this.timer = setInterval(() => {}, 1e8)
this.refHandle.ref()
}
this.count++
}

public decrease (): void {
if (this.count === 0) return
if (this.count === 1) {
clearInterval(this.timer)
this.timer = undefined
this.refHandle.unref()
}
this.count--
}
Expand Down

0 comments on commit a71cc25

Please sign in to comment.