Amp\Parallel\Context\Thread class Thread implements Amp\Parallel\Context\Context

Implements an execution context using native multi-threading.

The thread context is not itself threaded. A local instance of the context is maintained both in the context that creates the thread and in the thread itself.

Summary

Properties

Methods

Properties

Methods

supported — public function supported(): bool

Checks if threading is enabled.

run — public function run(callable $function, mixed ...$args): Amp\Parallel\Context\Thread

Creates and starts a new thread.

Type Parameter Description Default Value
callable $function The callable to invoke in the thread. First argument is an instance of \Amp\Parallel\Sync\Channel. none
mixed ... $args Additional arguments to pass to the given callable. none
__construct — public function __construct(callable $function, mixed ...$args)

Creates a new thread.

Type Parameter Description Default Value
callable $function The callable to invoke in the thread. First argument is an instance of \Amp\Parallel\Sync\Channel. none
mixed ... $args Additional arguments to pass to the given callable. none
__clone — public function __clone()

Returns the thread to the condition before starting. The new thread can be started and run independently of the first thread.

__destruct — public function __destruct()

Kills the thread if it is still running.

isRunning — public function isRunning(): bool

Checks if the context is running.

start — public function start()

Spawns the thread and begins the thread's execution.

kill — public function kill()

Immediately kills the context.

join — public function join(): Amp\Promise
No documentation.
receive — public function receive(): Amp\Promise
No documentation.
send — public function send($data): Amp\Promise
No documentation.
Type Parameter Description Default Value
mixed $data No documentation. none