mirror of
https://github.com/danog/parallel.git
synced 2024-11-26 20:34:40 +01:00
Add spawn shortcut for threads
This commit is contained in:
parent
d94f9441ba
commit
163ffb4f54
@ -28,6 +28,20 @@ class ThreadContext implements ContextInterface
|
||||
*/
|
||||
private $channel;
|
||||
|
||||
/**
|
||||
* Spawns a new thread and runs it.
|
||||
*
|
||||
* @param callable $function A callable to invoke in the thread.
|
||||
*
|
||||
* @return ThreadContext The thread object that was spawned.
|
||||
*/
|
||||
public static function spawn(callable $function /* , ...$args */)
|
||||
{
|
||||
$thread = new static($function);
|
||||
$thread->start();
|
||||
return $thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new thread context from a thread.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user