跳到主要内容

bn.createWorker

createWorker(scriptPath): Worker

description Create a Worker Thread.

example

const worker = bn.createWorker('workers/index.js')
worker.onMessage((msg) => console.log('worker message', msg)
worker.postMessage({ hello: 'world' })

Parameters

NameType
scriptPathstring

Returns

Worker

Interface: Worker

NameTypeDescription
postMessage(message): Promise<void>Main thread/Worker The message sent by the thread.
terminate(): Promise<void>End current Worker Threads. Only in the main thread worker Object.
onMessage(callback): Promise<void>Monitor main thread/Worker Event of a message sent by a thread to the current thread.

postMessage

postMessage(message): Promise<void>

Main thread/Worker The message sent by the thread.

Parameters

NameType
messageData

Returns

Promise<void>


terminate

terminate(): Promise<void>

End current Worker Threads. Only in the main thread worker Object.

Returns

Promise<void>


onMessage

onMessage(callback): Promise<void>

Monitor main thread/Worker Event of a message sent by a thread to the current thread.

Parameters

NameType
callbackonMessageCallback

Returns

Promise<void>

Data

Ƭ Data: Object


Interface: onMessageCallback

NameTypeDescription
onMessageCallbackvoid