Skip to content

Commit 5e1b13d

Browse files
committed
Clean up threads when done testing
1 parent 92d9c10 commit 5e1b13d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/RuntimeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WyriHaximus\React\Tests\Parallel;
44

55
use React\EventLoop\Factory;
6+
use React\Promise\ExtendedPromiseInterface;
67
use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
78
use WyriHaximus\React\Parallel\FutureToPromiseConverter;
89
use WyriHaximus\React\Parallel\Runtime;
@@ -18,12 +19,17 @@ public function testConvertSuccess(): void
1819
$loop = Factory::create();
1920
$runtime = new Runtime(new FutureToPromiseConverter($loop), \dirname(__DIR__) . '/vendor/autoload.php');
2021

22+
/** @var ExtendedPromiseInterface $promise */
2123
$promise = $runtime->run(function () {
2224
sleep(3);
2325

2426
return 3;
2527
});
2628

29+
$promise->always(function () use ($runtime): void {
30+
$runtime->close();
31+
});
32+
2733
$loop->run();
2834
$three = $this->await($promise, $loop, 3.3);
2935

@@ -38,12 +44,17 @@ public function testConvertFailure(): void
3844
$loop = Factory::create();
3945
$runtime = new Runtime(new FutureToPromiseConverter($loop), \dirname(__DIR__) . '/vendor/autoload.php');
4046

47+
/** @var ExtendedPromiseInterface $promise */
4148
$promise = $runtime->run(function (): void {
4249
sleep(3);
4350

4451
throw new \Exception('Rethrow exception');
4552
});
4653

54+
$promise->always(function () use ($runtime): void {
55+
$runtime->close();
56+
});
57+
4758
$loop->run();
4859
$three = $this->await($promise, $loop, 3.3);
4960

0 commit comments

Comments
 (0)