2016-12-30 02:16:04 +01:00
|
|
|
<?php
|
2015-08-28 23:58:15 +02:00
|
|
|
|
2017-11-29 22:01:32 +01:00
|
|
|
namespace Amp\Parallel\Test\Context;
|
2016-08-18 18:04:48 +02:00
|
|
|
|
2017-03-22 05:19:15 +01:00
|
|
|
use Amp\Loop;
|
2017-11-29 22:01:32 +01:00
|
|
|
use Amp\Parallel\Context\Thread;
|
2017-11-29 22:07:00 +01:00
|
|
|
use Amp\Parallel\Test\AbstractContextTest;
|
2015-08-28 23:58:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group threading
|
|
|
|
* @requires extension pthreads
|
|
|
|
*/
|
2016-08-19 00:36:58 +02:00
|
|
|
class ThreadTest extends AbstractContextTest {
|
|
|
|
public function createContext(callable $function) {
|
2015-09-26 06:41:15 +02:00
|
|
|
return new Thread($function);
|
2015-08-31 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-19 00:36:58 +02:00
|
|
|
public function testSpawnStartsThread() {
|
2017-03-16 23:03:59 +01:00
|
|
|
Loop::run(function () {
|
2015-08-31 01:25:44 +02:00
|
|
|
$thread = Thread::spawn(function () {
|
|
|
|
usleep(100);
|
|
|
|
});
|
|
|
|
|
2017-03-22 05:25:45 +01:00
|
|
|
$this->assertTrue($thread->isRunning());
|
|
|
|
|
2016-08-19 00:36:58 +02:00
|
|
|
return yield $thread->join();
|
2017-03-16 23:03:59 +01:00
|
|
|
});
|
2015-08-31 01:25:44 +02:00
|
|
|
}
|
2015-08-28 23:58:15 +02:00
|
|
|
}
|