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