repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore: v2.4.9
[poolifier.git]
/
src
/
worker
/
abstract-worker.ts
diff --git
a/src/worker/abstract-worker.ts
b/src/worker/abstract-worker.ts
index b588b181fa1720bb44fc8b76d4dbafe847743364..73eec1c6999d2aae78fa7e0a70038d30d6993997 100644
(file)
--- a/
src/worker/abstract-worker.ts
+++ b/
src/worker/abstract-worker.ts
@@
-41,7
+41,7
@@
export abstract class AbstractWorker<
public constructor (
type: string,
protected readonly isMain: boolean,
public constructor (
type: string,
protected readonly isMain: boolean,
- fn: (data: Data) => Response,
+ fn: (data: Data) => Response
| Promise<Response>
,
protected mainWorker: MainWorker | undefined | null,
protected readonly opts: WorkerOptions = {
/**
protected mainWorker: MainWorker | undefined | null,
protected readonly opts: WorkerOptions = {
/**
@@
-56,8
+56,8
@@
export abstract class AbstractWorker<
}
) {
super(type)
}
) {
super(type)
- this.checkFunctionInput(fn)
this.checkWorkerOptions(this.opts)
this.checkWorkerOptions(this.opts)
+ this.checkFunctionInput(fn)
if (!this.isMain) {
this.lastTaskTimestamp = performance.now()
this.aliveInterval = setInterval(
if (!this.isMain) {
this.lastTaskTimestamp = performance.now()
this.aliveInterval = setInterval(
@@
-83,9
+83,9
@@
export abstract class AbstractWorker<
*/
protected messageListener (
message: MessageValue<Data, MainWorker>,
*/
protected messageListener (
message: MessageValue<Data, MainWorker>,
- fn: (data: Data) => Response
+ fn: (data: Data) => Response
| Promise<Response>
): void {
): void {
- if (message.
data != null && message.id
!= null) {
+ if (message.
id != null && message.data
!= null) {
// Task message received
if (this.opts.async === true) {
this.runInAsyncScope(this.runAsync.bind(this), this, fn, message)
// Task message received
if (this.opts.async === true) {
this.runInAsyncScope(this.runAsync.bind(this), this, fn, message)
@@
-114,11
+114,18
@@
export abstract class AbstractWorker<
*
* @param fn - The function that should be defined.
*/
*
* @param fn - The function that should be defined.
*/
- private checkFunctionInput (fn: (data: Data) => Response): void {
+ private checkFunctionInput (
+ fn: (data: Data) => Response | Promise<Response>
+ ): void {
if (fn == null) throw new Error('fn parameter is mandatory')
if (typeof fn !== 'function') {
throw new TypeError('fn parameter is not a function')
}
if (fn == null) throw new Error('fn parameter is mandatory')
if (typeof fn !== 'function') {
throw new TypeError('fn parameter is not a function')
}
+ if (fn.constructor.name === 'AsyncFunction' && this.opts.async === false) {
+ throw new Error(
+ 'fn parameter is an async function, please set the async option to true'
+ )
+ }
}
/**
}
/**