Skip to content

Add Runtime stub #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions etc/qa/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ parameters:
- ReactParallel\EventLoop\CanceledFuture
- ReactParallel\EventLoop\KilledRuntime
stubFiles:
- ../../stubs/Channel.stub
- ../../stubs/Event.stub
- ../../stubs/Future.stub
- ../../stubs/functions.stub
- ../../stubs/Channel.stub
- ../../stubs/Future.stub
- ../../stubs/Runtime.stub

includes:
- ../../vendor/wyrihaximus/async-test-utilities/rules.neon
1 change: 1 addition & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ parameters:
- stubs/Event.stub
- stubs/functions.stub
- stubs/Future.stub
- stubs/Runtime.stub
60 changes: 60 additions & 0 deletions stubs/Runtime.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace parallel;

use Closure;

/**
* Each runtime represents a single PHP thread, the thread is created (and bootstrapped) upon construction. The thread
* then waits for tasks to be scheduled: Scheduled tasks will be executed FIFO and then the thread will resume waiting
* until more tasks are scheduled, or it's closed, killed, or destroyed by the normal scoping rules of PHP objects.
*
* Warning: When a runtime is destroyed by the normal scoping rules of PHP objects, it will first execute all of the
* tasks that were scheduled, and block while doing so.
*
* When a new runtime is created, it does not share code with the thread (or process) that created it. This means it
* doesn't have the same classes and functions loaded, nor the same autoloader set. In some cases, a very lightweight
* runtime is desirable because the tasks that will be scheduled do not need access to the code in the parent thread.
* In those cases where the tasks do need to access the same code, it is enough to set an autoloader as the bootstrap.
*
* Note: preloading may be used in conjunction with parallel, in this case preloaded code is available without
* bootstrapping
*/
final class Runtime
{
/* Create */

/**
* @throws Runtime\Error if thread could not be created
* @throws Runtime\Error\Bootstrap if bootstrapping failed
*/
public function __construct(?string $bootstrap = null) {}

/* Execute */

/**
* @param (Closure():T)|(Closure():void) $task
* @param array<mixed> $argv
* @template T
* @return ($task is (Closure():T) ? Future<T> : null)
*
* @throws Runtime\Error\Closed if \parallel\Runtime was closed.
* @throws Runtime\Error\IllegalFunction if task is a closure created from an internal function.
* @throws Runtime\Error\IllegalInstruction if task contains illegal instructions.
* @throws Runtime\Error\IllegalParameter if task accepts or argv contains illegal variables.
* @throws Runtime\Error\IllegalReturn if task returns illegally.
*/
public function run(Closure $task, ?array $argv = null): ?Future {}

/* Join */

/**
* @throws Runtime\Error\Closed if Runtime was already closed.
*/
public function close(): void {}

/**
* @throws Runtime\Error\Closed if Runtime was closed.
*/
public function kill(): void {}
}
Loading