Module jls.util.SerialWorker
Executes functions in a dedicated thread.
This is a simplified Worker that allow to execute arbitrary functions in a dedicated thread. A single argument could be passed to the function and the function first result will be returned to the caller.
Usage:
local serialWorker = SerialWorker:new() serialWorker:call(function(name) return 'Hi '..tostring(name) -- executed in a dedicated thread end, 'John'):next(function(greetings) print(greetings) -- prints 'Hi John' in the current thread serialWorker:close() end) event:loop()
Class SerialWorker
SerialWorker:new () | Creates a new SerialWorker. |
serialWorker:call (fn[, data[, sh]]) | Calls the specified function. |
serialWorker:close () | Closes this worker. |
Class SerialWorker
The SerialWorker class.
- SerialWorker:new ()
- Creates a new SerialWorker.
- serialWorker:call (fn[, data[, sh]])
-
Calls the specified function.
Parameters:
- fn function the function to call.
- data the function argument. (optional)
- sh a stream handler for intermediate results. (optional)
Returns:
-
jls.lang.Promise
a promise that resolves once the function has been called.
- serialWorker:close ()
- Closes this worker.