wilton/thread
Run background threads.
More...
Functions | |
| Object | run (Object options, Function|Undefined callback) |
| Start specified function in the background thread. | |
| Undefined | sleepMillis (Number millis, Function|Undefined callback) |
| Stops the execution of the current thread for the specified time period. | |
This module allows to run specified function in the background OS-thread.
Different threads have separate JavaScript runtime contexts and do not share JavaScript objects in memory. wilton/Channel or wilton/shared modules may be used for inter-thread communication.
Started background threads are daemon (detached) and should be stopped (e.g. using application level synchronization) before the application shutdown.
Usage example:
| Object thread::run | ( | Object | options, |
| Function|Undefined | callback | ||
| ) |
Starts the new OS-thread and runs specified function (found inside the specified module) in this thread.
This function returns immediately.
| options | Object configuration object, see possible options below |
| callback | Function|Undefined callback to receive result or error |
Object Channel object where thread will send a message on its exitOptions
Object module path and function name to run from background threadString full name of JavaScript module to loadString|Undefined name of the function contained in the specified module, if function is not specified, only module will be loaded (its top-level code will be executed)Array|Undefined optional list of arguments, that will be passed to specified functionString|Undefined the name of the Channel, that will be created for this thread; thread will send the message to this channel on exit; default value: callbackScript.moduleArray|Undefined list of the wiltoncall calls names allowed to be used from the spawned thread; if this parameter is not specified, then capabilities checks are not performed for the spawned thread | Undefined thread::sleepMillis | ( | Number | millis, |
| Function|Undefined | callback | ||
| ) |
Maked current thread to sleep for specified amount of milliseconds.
| millis | Number amount of milliseconds to sleep |
| callback | Function|Undefined callback to receive result or error |
Undefined
1.8.1.2