summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
658b9aa)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
void (this.destroyWorker(worker) as Promise<void>)
}
})
void (this.destroyWorker(worker) as Promise<void>)
}
})
- this.sendToWorker(worker, { dynamic: true })
+ this.sendToWorker(worker, { checkAlive: true })
/** @inheritDoc */
protected destroyWorker (worker: Worker): void {
/** @inheritDoc */
protected destroyWorker (worker: Worker): void {
- this.sendToWorker(worker, { kill: 1 })
+ this.sendToWorker(worker, { kill: true })
worker.on('disconnect', () => {
worker.kill()
})
worker.on('disconnect', () => {
worker.kill()
})
/** @inheritDoc */
protected async destroyWorker (worker: Worker): Promise<void> {
/** @inheritDoc */
protected async destroyWorker (worker: Worker): Promise<void> {
- this.sendToWorker(worker, { kill: 1 })
+ this.sendToWorker(worker, { kill: true })
await worker.terminate()
}
await worker.terminate()
}
- readonly kill?: KillBehavior | 1
+ readonly kill?: KillBehavior | true
*/
readonly started?: boolean
/**
*/
readonly started?: boolean
/**
- * Whether the worker is dynamic or not.
+ * Whether the worker starts or stops its aliveness check.
- readonly dynamic?: boolean
+ readonly checkAlive?: boolean
if (message.statistics != null) {
// Statistics message received
this.statistics = message.statistics
if (message.statistics != null) {
// Statistics message received
this.statistics = message.statistics
- } else if (message.dynamic === true) {
- // Worker dynamic message received
- this.startCheckAlive()
+ } else if (message.checkAlive != null) {
+ // Check alive message received
+ message.checkAlive ? this.startCheckAlive() : this.stopCheckAlive()
} else if (message.id != null && message.data != null) {
// Task message received
const fn = this.getTaskFunction(message.name)
} else if (message.id != null && message.data != null) {
// Task message received
const fn = this.getTaskFunction(message.name)
} else {
this.runInAsyncScope(this.runSync.bind(this), this, fn, message)
}
} else {
this.runInAsyncScope(this.runSync.bind(this), this, fn, message)
}
- } else if (message.kill != null) {
+ } else if (message.kill === true) {
- this.aliveInterval != null && clearInterval(this.aliveInterval)
+ /**
+ * Starts the worker alive check interval.
+ */
private startCheckAlive (): void {
this.lastTaskTimestamp = performance.now()
this.aliveInterval = setInterval(
private startCheckAlive (): void {
this.lastTaskTimestamp = performance.now()
this.aliveInterval = setInterval(
this.checkAlive.bind(this)()
}
this.checkAlive.bind(this)()
}
+ /**
+ * Stops the worker alive check interval.
+ */
+ private stopCheckAlive (): void {
+ this.aliveInterval != null && clearInterval(this.aliveInterval)
+ }
+
+ /**
+ * Checks if the worker should be terminated, because its living too long.
+ */
+ private checkAlive (): void {
+ if (
+ performance.now() - this.lastTaskTimestamp >
+ (this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME)
+ ) {
+ this.sendToMainWorker({ kill: this.opts.killBehavior })
+ }
+ }
+
/**
* Returns the main worker.
*
/**
* Returns the main worker.
*
message: MessageValue<Response, Data>
): void
message: MessageValue<Response, Data>
): void
- /**
- * Checks if the worker should be terminated, because its living too long.
- */
- protected checkAlive (): void {
- if (
- performance.now() - this.lastTaskTimestamp >
- (this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME)
- ) {
- this.sendToMainWorker({ kill: this.opts.killBehavior })
- }
- }
-
/**
* Handles an error and convert it to a string so it can be sent back to the main worker.
*
/**
* Handles an error and convert it to a string so it can be sent back to the main worker.
*