From e8ea58d292e381a6be7f4d0fee5d5b691adb37ac Mon Sep 17 00:00:00 2001 From: aardizio Date: Tue, 16 Feb 2021 14:05:48 +0100 Subject: [PATCH] Change killBehaviorEnumeration to killBehaviorTypes --- src/index.ts | 2 +- src/pools/cluster/dynamic.ts | 4 ++-- src/pools/thread/dynamic.ts | 4 ++-- src/worker/abstract-worker.ts | 2 +- src/worker/worker-options.ts | 2 +- tests/worker/cluster/asyncErrorWorker.js | 4 ++-- tests/worker/cluster/asyncWorker.js | 4 ++-- tests/worker/cluster/echoWorker.js | 4 ++-- tests/worker/cluster/emptyWorker.js | 4 ++-- tests/worker/cluster/errorWorker.js | 4 ++-- tests/worker/cluster/longRunningWorkerHardBehavior.js | 4 ++-- tests/worker/cluster/testWorker.js | 4 ++-- tests/worker/thread/asyncWorker.js | 4 ++-- tests/worker/thread/echoWorker.js | 4 ++-- tests/worker/thread/emptyWorker.js | 4 ++-- tests/worker/thread/errorWorker.js | 4 ++-- tests/worker/thread/longRunningWorkerHardBehavior.js | 4 ++-- tests/worker/thread/testWorker.js | 4 ++-- 18 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/index.ts b/src/index.ts index 60536f99..b64a274b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,4 +16,4 @@ export { AbstractWorker } from './worker/abstract-worker' export { ClusterWorker } from './worker/cluster-worker' export { ThreadWorker } from './worker/thread-worker' export type { WorkerOptions } from './worker/worker-options' -export { killBehaviorEnumeration } from './worker/worker-options' +export { killBehaviorTypes } from './worker/worker-options' diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 58e2b712..eb93c0c8 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -2,7 +2,7 @@ import type { Worker } from 'cluster' import type { JSONValue } from '../../utility-types' import type { ClusterPoolOptions } from './fixed' import { FixedClusterPool } from './fixed' -import { killBehaviorEnumeration } from '../../worker/worker-options' +import { killBehaviorTypes } from '../../worker/worker-options' /** * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers. @@ -64,7 +64,7 @@ export class DynamicClusterPool< this.registerWorkerMessageListener(worker, message => { const tasksInProgress = this.tasks.get(worker) const isKillBehaviorOptionHard = - message.kill === killBehaviorEnumeration.HARD + message.kill === killBehaviorTypes.HARD if (isKillBehaviorOptionHard || tasksInProgress === 0) { // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime) this.sendToWorker(worker, { kill: 1 }) diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 7a0d4ffd..f068b4a2 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -2,7 +2,7 @@ import type { JSONValue } from '../../utility-types' import type { PoolOptions } from '../abstract-pool' import type { ThreadWorkerWithMessageChannel } from './fixed' import { FixedThreadPool } from './fixed' -import { killBehaviorEnumeration } from '../../worker/worker-options' +import { killBehaviorTypes } from '../../worker/worker-options' /** * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads. @@ -64,7 +64,7 @@ export class DynamicThreadPool< this.registerWorkerMessageListener(worker, message => { const tasksInProgress = this.tasks.get(worker) const isKillBehaviorOptionHard = - message.kill === killBehaviorEnumeration.HARD + message.kill === killBehaviorTypes.HARD if (isKillBehaviorOptionHard || tasksInProgress === 0) { // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime) this.sendToWorker(worker, { kill: 1 }) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index cb33188e..b65ed590 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -3,7 +3,7 @@ import type { Worker } from 'cluster' import type { MessagePort } from 'worker_threads' import type { MessageValue, KillBehavior } from '../utility-types' import type { WorkerOptions } from './worker-options' -// import { killBehaviorEnumeration } from './worker-options' +// import { killBehaviorTypes } from './worker-options' const defaultMaxInactiveTime = 1000 * 60 // TODO fix this and avoid that SOFT/HARD words are replicated so much times into the project diff --git a/src/worker/worker-options.ts b/src/worker/worker-options.ts index b1d13d0c..bdad1a8d 100644 --- a/src/worker/worker-options.ts +++ b/src/worker/worker-options.ts @@ -3,7 +3,7 @@ import type { KillBehavior } from '../utility-types' /** * Kill behavior enumeration */ -export const killBehaviorEnumeration = Object.freeze({ +export const killBehaviorTypes = Object.freeze({ SOFT: 'SOFT', HARD: 'HARD' }) diff --git a/tests/worker/cluster/asyncErrorWorker.js b/tests/worker/cluster/asyncErrorWorker.js index be675e11..f3e0e7c8 100644 --- a/tests/worker/cluster/asyncErrorWorker.js +++ b/tests/worker/cluster/asyncErrorWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') async function error (data) { return new Promise((resolve, reject) => { @@ -13,5 +13,5 @@ async function error (data) { module.exports = new ClusterWorker(error, { maxInactiveTime: 500, async: true, - killBehavior: killBehaviorEnumeration + killBehavior: killBehaviorTypes }) diff --git a/tests/worker/cluster/asyncWorker.js b/tests/worker/cluster/asyncWorker.js index b47adc91..106df109 100644 --- a/tests/worker/cluster/asyncWorker.js +++ b/tests/worker/cluster/asyncWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') async function sleep (data) { return new Promise((resolve, reject) => { @@ -10,5 +10,5 @@ async function sleep (data) { module.exports = new ClusterWorker(sleep, { maxInactiveTime: 500, async: true, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/cluster/echoWorker.js b/tests/worker/cluster/echoWorker.js index 8d4477ee..77898bac 100644 --- a/tests/worker/cluster/echoWorker.js +++ b/tests/worker/cluster/echoWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') function echo (data) { return data @@ -7,5 +7,5 @@ function echo (data) { module.exports = new ClusterWorker(echo, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/cluster/emptyWorker.js b/tests/worker/cluster/emptyWorker.js index 4e5eeca7..979057c2 100644 --- a/tests/worker/cluster/emptyWorker.js +++ b/tests/worker/cluster/emptyWorker.js @@ -1,9 +1,9 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') function test (data) {} module.exports = new ClusterWorker(test, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/cluster/errorWorker.js b/tests/worker/cluster/errorWorker.js index bbcb78be..02168a67 100644 --- a/tests/worker/cluster/errorWorker.js +++ b/tests/worker/cluster/errorWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') function error (data) { throw new Error('Error Message from ClusterWorker') @@ -8,5 +8,5 @@ function error (data) { module.exports = new ClusterWorker(error, { maxInactiveTime: 500, async: false, - killBehavior: killBehaviorEnumeration + killBehavior: killBehaviorTypes }) diff --git a/tests/worker/cluster/longRunningWorkerHardBehavior.js b/tests/worker/cluster/longRunningWorkerHardBehavior.js index 9fe9d3f8..4dc69525 100644 --- a/tests/worker/cluster/longRunningWorkerHardBehavior.js +++ b/tests/worker/cluster/longRunningWorkerHardBehavior.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') async function sleep (data) { return new Promise((resolve, reject) => { @@ -10,5 +10,5 @@ async function sleep (data) { module.exports = new ClusterWorker(sleep, { maxInactiveTime: 500, async: true, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/cluster/testWorker.js b/tests/worker/cluster/testWorker.js index 3e1ed0d1..9b95294b 100644 --- a/tests/worker/cluster/testWorker.js +++ b/tests/worker/cluster/testWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ClusterWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ClusterWorker, killBehaviorTypes } = require('../../../lib/index') const { isMaster } = require('cluster') function test (data) { @@ -14,5 +14,5 @@ function test (data) { module.exports = new ClusterWorker(test, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/thread/asyncWorker.js b/tests/worker/thread/asyncWorker.js index 59a900e9..a6a9590d 100644 --- a/tests/worker/thread/asyncWorker.js +++ b/tests/worker/thread/asyncWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ThreadWorker, killBehaviorTypes } = require('../../../lib/index') async function sleep (data) { return new Promise((resolve, reject) => { @@ -10,5 +10,5 @@ async function sleep (data) { module.exports = new ThreadWorker(sleep, { maxInactiveTime: 500, async: true, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/thread/echoWorker.js b/tests/worker/thread/echoWorker.js index 3b554ccc..9471891e 100644 --- a/tests/worker/thread/echoWorker.js +++ b/tests/worker/thread/echoWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ThreadWorker, killBehaviorTypes } = require('../../../lib/index') function echo (data) { return data @@ -7,5 +7,5 @@ function echo (data) { module.exports = new ThreadWorker(echo, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/thread/emptyWorker.js b/tests/worker/thread/emptyWorker.js index c7034caa..1787a79c 100644 --- a/tests/worker/thread/emptyWorker.js +++ b/tests/worker/thread/emptyWorker.js @@ -1,9 +1,9 @@ 'use strict' -const { ThreadWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ThreadWorker, killBehaviorTypes } = require('../../../lib/index') function test (data) {} module.exports = new ThreadWorker(test, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/thread/errorWorker.js b/tests/worker/thread/errorWorker.js index 6b7ee3c9..7f7fdadd 100644 --- a/tests/worker/thread/errorWorker.js +++ b/tests/worker/thread/errorWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ThreadWorker, killBehaviorTypes } = require('../../../lib/index') function error (data) { throw new Error(data) @@ -7,5 +7,5 @@ function error (data) { module.exports = new ThreadWorker(error, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/thread/longRunningWorkerHardBehavior.js b/tests/worker/thread/longRunningWorkerHardBehavior.js index ec745794..8e3eb38a 100644 --- a/tests/worker/thread/longRunningWorkerHardBehavior.js +++ b/tests/worker/thread/longRunningWorkerHardBehavior.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ThreadWorker, killBehaviorTypes } = require('../../../lib/index') async function sleep (data) { return new Promise((resolve, reject) => { @@ -10,5 +10,5 @@ async function sleep (data) { module.exports = new ThreadWorker(sleep, { maxInactiveTime: 500, async: true, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) diff --git a/tests/worker/thread/testWorker.js b/tests/worker/thread/testWorker.js index 77dfdc8e..7510f00b 100644 --- a/tests/worker/thread/testWorker.js +++ b/tests/worker/thread/testWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { ThreadWorker, killBehaviorEnumeration } = require('../../../lib/index') +const { ThreadWorker, killBehaviorTypes } = require('../../../lib/index') const { isMainThread } = require('worker_threads') function test (data) { @@ -14,5 +14,5 @@ function test (data) { module.exports = new ThreadWorker(test, { maxInactiveTime: 500, - killBehavior: killBehaviorEnumeration.HARD + killBehavior: killBehaviorTypes.HARD }) -- 2.34.1