2015-08-28 23:58:15 +02:00
|
|
|
<?php
|
2015-08-31 20:30:07 +02:00
|
|
|
namespace Icicle\Tests\Concurrent\Threading;
|
2015-08-28 23:58:15 +02:00
|
|
|
|
2015-09-02 23:34:42 +02:00
|
|
|
use Icicle\Concurrent\Sync\Internal\ExitSuccess;
|
2015-08-28 23:58:15 +02:00
|
|
|
use Icicle\Concurrent\Threading\Thread;
|
|
|
|
use Icicle\Coroutine;
|
|
|
|
use Icicle\Loop;
|
2015-09-26 06:41:15 +02:00
|
|
|
use Icicle\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);
|
|
|
|
});
|
|
|
|
|
|
|
|
yield $thread->join();
|
|
|
|
})->done();
|
|
|
|
|
|
|
|
Loop\run();
|
|
|
|
}
|
2015-08-28 23:58:15 +02:00
|
|
|
}
|