Worker
struct Worker
A worker object that can send and receive messages to worker.
Methods
recv
pub fn recv<T>(self): T? throws RecvMessageError
Receive a message from the worker.
recv
pub fn recv<T>(self): T? throws RecvMessageError
Receive a message from the worker.
Receive a message from the worker.
Returns nil
if the worker has been terminated.
send
pub fn send<T>(self, msg: T) throws SendMessageError
Send a message to the worker.
send
pub fn send<T>(self, msg: T) throws SendMessageError
Send a message to the worker.
Send a message to the worker.
create
pub fn create(f: |(Worker)|): Worker throws CreateWorkerError
Spawn a new worker with the given closure.
create
pub fn create(f: |(Worker)|): Worker throws CreateWorkerError
Spawn a new worker with the given closure.
Spawn a new worker with the given closure.
The closure will be executed in the new worker.
Example
nv
use std.worker.Worker;
fn main() throws {
let worker = try Worker.create(|worker| {
let msg = try worker.recv::<string>();
try worker.send(msg.to_uppercase());
});
try worker.send("Hello, world!");
let msg = try worker.recv::<string>();
assert_eq msg, "HELLO, WORLD!";
}
pool
pub fn pool<T, R>(f: |(T)|: T, n: int = vm.num_cpus()): WorkerPool<T, T> throws CreateWorkerError
[src]
pub fn pool<T, R>(
f: |(T): R throws|, n: int = vm.num_cpus()
): WorkerPool<T, R> throws CreateWorkerError {
return try Worker._pool(f, n);
}
Create a new worker pool with the given number of workers.
pool
pub fn pool<T, R>(f: |(T)|: T, n: int = vm.num_cpus()): WorkerPool<T, T> throws CreateWorkerError
[src]
pub fn pool<T, R>(
f: |(T): R throws|, n: int = vm.num_cpus()
): WorkerPool<T, R> throws CreateWorkerError {
return try Worker._pool(f, n);
}
Create a new worker pool with the given number of workers.
Create a new worker pool with the given number of workers.