1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 18:47:50 +01:00
parallel/test/Thread/ThreadedParcelTest.php

35 lines
906 B
PHP
Raw Normal View History

2017-11-29 21:40:07 +01:00
<?php
namespace Amp\Parallel\Test\Thread;
use Amp\Loop;
use Amp\Parallel\Test\Sync\AbstractParcelTest;
use Amp\Parallel\Thread\Thread;
use Amp\Parallel\Thread\ThreadedParcel;
/**
* @requires extension pthreads
*/
class ThreadedParcelTest extends AbstractParcelTest {
protected function createParcel($value) {
return new ThreadedParcel($value);
}
public function testWithinThread() {
Loop::run(function () {
$value = 1;
$parcel = new ThreadedParcel($value);
$thread = Thread::spawn(function (ThreadedParcel $parcel) {
$parcel->synchronized(function (int $value) {
return $value + 1;
});
return 0;
}, $parcel);
$this->assertSame(0, yield $thread->join());
$this->assertSame($value + 1, yield $parcel->unwrap());
});
}
}