new Worker(mainFn, options)
Parameters:
| Name | Type | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
mainFn |
function | main worker function |
||||||||
options |
object |
Properties
|
Methods
-
onMessage(fn)
-
Set onMessage callback
Parameters:
Name Type Description fnfunction a callback function to get worker result
-
postMessage(message [, restart])
-
Post a new message to the worker
Parameters:
Name Type Argument Default Description messageobject restartboolean <optional>
false stop the worker and restart a new one
-
start()
-
Terminate current worker and start a new one
-
terminate()
-
Terminate a worker