2015-08-28 23:58:15 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-18 18:04:48 +02:00
|
|
|
namespace Amp\Tests\Concurrent\Threading;
|
|
|
|
|
|
|
|
use Amp\Concurrent\Threading\Thread;
|
|
|
|
use Amp\Coroutine;
|
|
|
|
use Amp\Loop;
|
|
|
|
use Amp\Tests\Concurrent\AbstractContextTest;
|
2015-08-28 23:58:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group threading
|
|
|
|
* @requires extension pthreads
|
|
|
|
*/
|
2015-09-26 06:41:15 +02:00
|
|
|
class ThreadTest extends AbstractContextTest
|
2015-08-28 23:58:15 +02:00
|
|
|
{
|
2015-09-26 06:41:15 +02:00
|
|
|
public function createContext(callable $function)
|
2015-09-02 23:34:42 +02:00
|
|
|
{
|
2015-09-26 06:41:15 +02:00
|
|
|
return new Thread($function);
|
2015-08-31 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSpawnStartsThread()
|
|
|
|
{
|
|
|
|
Coroutine\create(function () {
|
|
|
|
$thread = Thread::spawn(function () {
|
|
|
|
usleep(100);
|
|
|
|
});
|
|
|
|
|
2016-01-23 07:00:56 +01:00
|
|
|
return yield from $thread->join();
|
2015-08-31 01:25:44 +02:00
|
|
|
})->done();
|
|
|
|
|
|
|
|
Loop\run();
|
|
|
|
}
|
2015-08-28 23:58:15 +02:00
|
|
|
}
|