Skip to content

Commit bb4b3d6

Browse files
committed
Runtime wrapper
1 parent b9906b1 commit bb4b3d6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

src/Runtime.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace WyriHaximus\React\Parallel;
4+
5+
use parallel\Runtime as ParallelRuntime;
6+
use React\Promise\PromiseInterface;
7+
8+
final class Runtime
9+
{
10+
/** @var string */
11+
private $id;
12+
13+
/** @var ParallelRuntime */
14+
private $runtime;
15+
16+
/** @var FutureToPromiseConverter */
17+
private $futureToPromiseConverter;
18+
19+
public function __construct(FutureToPromiseConverter $futureToPromiseConverter, string $autoload)
20+
{
21+
$this->runtime = new ParallelRuntime($autoload);
22+
$this->id = spl_object_hash($this->runtime);
23+
$this->futureToPromiseConverter = $futureToPromiseConverter;
24+
}
25+
26+
public function run(callable $callable, ...$args): PromiseInterface
27+
{
28+
return $this->futureToPromiseConverter->convert(
29+
$this->runtime->run($callable, $args)
30+
);
31+
}
32+
33+
public function close()
34+
{
35+
$this->runtime->close();
36+
}
37+
38+
public function kill()
39+
{
40+
$this->runtime->kill();
41+
}
42+
}

0 commit comments

Comments
 (0)