Skip to content

Commit b1782e3

Browse files
authored
Merge pull request #7 from reactphp-parallel/add-runtime-stub
Add Runtime stub
2 parents ff087ee + d6ae364 commit b1782e3

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

etc/qa/phpstan.neon

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ parameters:
77
- ReactParallel\EventLoop\CanceledFuture
88
- ReactParallel\EventLoop\KilledRuntime
99
stubFiles:
10+
- ../../stubs/Channel.stub
1011
- ../../stubs/Event.stub
11-
- ../../stubs/Future.stub
1212
- ../../stubs/functions.stub
13-
- ../../stubs/Channel.stub
13+
- ../../stubs/Future.stub
14+
- ../../stubs/Runtime.stub
1415

1516
includes:
1617
- ../../vendor/wyrihaximus/async-test-utilities/rules.neon

extension.neon

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ parameters:
44
- stubs/Event.stub
55
- stubs/functions.stub
66
- stubs/Future.stub
7+
- stubs/Runtime.stub

stubs/Runtime.stub

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace parallel;
4+
5+
use Closure;
6+
7+
/**
8+
* Each runtime represents a single PHP thread, the thread is created (and bootstrapped) upon construction. The thread
9+
* then waits for tasks to be scheduled: Scheduled tasks will be executed FIFO and then the thread will resume waiting
10+
* until more tasks are scheduled, or it's closed, killed, or destroyed by the normal scoping rules of PHP objects.
11+
*
12+
* Warning: When a runtime is destroyed by the normal scoping rules of PHP objects, it will first execute all of the
13+
* tasks that were scheduled, and block while doing so.
14+
*
15+
* When a new runtime is created, it does not share code with the thread (or process) that created it. This means it
16+
* doesn't have the same classes and functions loaded, nor the same autoloader set. In some cases, a very lightweight
17+
* runtime is desirable because the tasks that will be scheduled do not need access to the code in the parent thread.
18+
* In those cases where the tasks do need to access the same code, it is enough to set an autoloader as the bootstrap.
19+
*
20+
* Note: preloading may be used in conjunction with parallel, in this case preloaded code is available without
21+
* bootstrapping
22+
*/
23+
final class Runtime
24+
{
25+
/* Create */
26+
27+
/**
28+
* @throws Runtime\Error if thread could not be created
29+
* @throws Runtime\Error\Bootstrap if bootstrapping failed
30+
*/
31+
public function __construct(?string $bootstrap = null) {}
32+
33+
/* Execute */
34+
35+
/**
36+
* @param (Closure():T)|(Closure():void) $task
37+
* @param array<mixed> $argv
38+
* @template T
39+
* @return ($task is (Closure():T) ? Future<T> : null)
40+
*
41+
* @throws Runtime\Error\Closed if \parallel\Runtime was closed.
42+
* @throws Runtime\Error\IllegalFunction if task is a closure created from an internal function.
43+
* @throws Runtime\Error\IllegalInstruction if task contains illegal instructions.
44+
* @throws Runtime\Error\IllegalParameter if task accepts or argv contains illegal variables.
45+
* @throws Runtime\Error\IllegalReturn if task returns illegally.
46+
*/
47+
public function run(Closure $task, ?array $argv = null): ?Future {}
48+
49+
/* Join */
50+
51+
/**
52+
* @throws Runtime\Error\Closed if Runtime was already closed.
53+
*/
54+
public function close(): void {}
55+
56+
/**
57+
* @throws Runtime\Error\Closed if Runtime was closed.
58+
*/
59+
public function kill(): void {}
60+
}

0 commit comments

Comments
 (0)