mirror of
https://github.com/danog/parallel.git
synced 2025-01-22 05:51:14 +01:00
spawn → run
This commit is contained in:
parent
852f580915
commit
4d99a9d968
@ -12,7 +12,7 @@ use Amp\Parallel\Sync\ThreadedParcel;
|
||||
Loop::run(function () {
|
||||
$parcel = new ThreadedParcel(1);
|
||||
|
||||
$context = Thread::spawn(function (Channel $channel, Parcel $parcel) {
|
||||
$context = Thread::run(function (Channel $channel, Parcel $parcel) {
|
||||
$value = yield $parcel->synchronized(function (int $value) {
|
||||
return $value + 1;
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ Loop::run(function () {
|
||||
|
||||
try {
|
||||
// Create a new child process that does some blocking stuff.
|
||||
$context = Process::spawn(__DIR__ . "/blocking-process.php");
|
||||
$context = Process::run(__DIR__ . "/blocking-process.php");
|
||||
|
||||
print "Waiting 2 seconds to send start data...\n";
|
||||
yield new Delayed(2000);
|
||||
|
@ -16,7 +16,7 @@ Loop::run(function () {
|
||||
|
||||
try {
|
||||
// Create a new child thread that does some blocking stuff.
|
||||
$context = Thread::spawn(function (Channel $channel): \Generator {
|
||||
$context = Thread::run(function (Channel $channel): \Generator {
|
||||
printf("Received the following from parent: %s\n", yield $channel->receive());
|
||||
|
||||
print "Sleeping for 3 seconds...\n";
|
||||
|
@ -33,7 +33,7 @@ class Process implements Context {
|
||||
*
|
||||
* @return \Amp\Parallel\Context\Process
|
||||
*/
|
||||
public static function spawn($script, string $binary = null): self {
|
||||
public static function run($script, string $binary = null): self {
|
||||
$process = new self($script, $binary);
|
||||
$process->start();
|
||||
return $process;
|
||||
|
@ -51,7 +51,7 @@ class Thread implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a new thread and runs it.
|
||||
* Creates and starts a new thread.
|
||||
*
|
||||
* @param callable $function The callable to invoke in the thread. First argument is an instance of
|
||||
* \Amp\Parallel\Sync\Channel.
|
||||
@ -59,7 +59,7 @@ class Thread implements Context {
|
||||
*
|
||||
* @return Thread The thread object that was spawned.
|
||||
*/
|
||||
public static function spawn(callable $function, ...$args): self {
|
||||
public static function run(callable $function, ...$args): self {
|
||||
$thread = new self($function, ...$args);
|
||||
$thread->start();
|
||||
return $thread;
|
||||
|
@ -16,7 +16,7 @@ class ThreadTest extends AbstractContextTest {
|
||||
|
||||
public function testSpawnStartsThread() {
|
||||
Loop::run(function () {
|
||||
$thread = Thread::spawn(function () {
|
||||
$thread = Thread::run(function () {
|
||||
usleep(100);
|
||||
});
|
||||
|
||||
|
@ -20,7 +20,7 @@ class ThreadedParcelTest extends AbstractParcelTest {
|
||||
$value = 1;
|
||||
$parcel = new ThreadedParcel($value);
|
||||
|
||||
$thread = Thread::spawn(function (Channel $channel, ThreadedParcel $parcel) {
|
||||
$thread = Thread::run(function (Channel $channel, ThreadedParcel $parcel) {
|
||||
$parcel->synchronized(function (int $value) {
|
||||
return $value + 1;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user