diff --git a/.gitignore b/.gitignore
index 2576532..638300f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ vendor/
*.csr
*.local
temp
+test.php
diff --git a/Coroutine/Coroutine.php b/Coroutine/Coroutine.php
index a3373b8..9708014 100644
--- a/Coroutine/Coroutine.php
+++ b/Coroutine/Coroutine.php
@@ -4,11 +4,12 @@
namespace Async;
-use Async\Spawn\Thread;
use Async\Spawn\Future;
use Async\Spawn\FutureHandler;
use Async\Spawn\FutureInterface;
use Async\Spawn\ChanneledInterface;
+use Async\Threads\Thread;
+use Async\Threads\TWorker;
use Async\Kernel;
use Async\Task;
use Async\Parallel;
@@ -488,7 +489,7 @@ public function addFuture($callable, int $timeout = 0, bool $display = false, $c
return $display ? $future->displayOn() : $future;
}
- public function addThread(int $tid, callable $callable, ...$args): Thread
+ public function addThread(int $tid, callable $callable, ...$args): TWorker
{
return $this->thread->create($tid, $callable, ...$args);
}
diff --git a/Coroutine/CoroutineInterface.php b/Coroutine/CoroutineInterface.php
index 50fcae2..e67e6e9 100644
--- a/Coroutine/CoroutineInterface.php
+++ b/Coroutine/CoroutineInterface.php
@@ -8,7 +8,8 @@
use Async\Spawn\Channeled;
use Async\Spawn\FutureInterface;
use Async\RuntimeException;
-use Async\Spawn\Thread;
+use Async\Threads\Thread;
+use Async\Threads\TWorker;
interface CoroutineInterface
{
@@ -304,9 +305,9 @@ public function addFuture($callable, int $timeout = 0, bool $display = false, $c
* @param string|int $tid Thread ID
* @param callable $callable
* @param mixed ...$args
- * @return Thread
+ * @return TWorker
*/
- public function addThread(int $tid, callable $callable, ...$args): Thread;
+ public function addThread(int $tid, callable $callable, ...$args): TWorker;
/**
* There are no **UV** file system operations/events pending.
diff --git a/Coroutine/Kernel.php b/Coroutine/Kernel.php
index 6e602c0..3a29ade 100644
--- a/Coroutine/Kernel.php
+++ b/Coroutine/Kernel.php
@@ -21,7 +21,8 @@
use Async\Misc\ContextInterface;
use Async\Misc\Semaphore;
use Async\Misc\TimeoutAfter;
-use Async\Spawn\Thread;
+use Async\Threads\Thread;
+use Async\Threads\TWorker;
use Async\Spawn\Channeled;
use Async\Spawn\FutureInterface;
use Psr\Container\ContainerInterface;
@@ -275,7 +276,7 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($tid, $custom
$error = ($isContext || $type) ? new TaskCancelled("Task {$tid}!") : new CancelledError("Task {$tid}!");
$customData = $cancelTask->getCustomData();
- if ($customData instanceof FutureInterface || $customData instanceof Thread) {
+ if ($customData instanceof FutureInterface || $customData instanceof Thread || $customData instanceof TWorker) {
$task->sendValue(true);
$cancelTask->setCaller($task);
if ($customData instanceof FutureInterface) {
@@ -334,7 +335,7 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($tid) {
}
$customData = $join->getCustomData();
- if ($customData instanceof Thread) {
+ if ($customData instanceof Thread || $customData instanceof TWorker) {
$coroutine->schedule($join);
return $customData->join($tid);
}
@@ -1168,7 +1169,7 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($callable, $t
$callableTask = $coroutine->getTask($taskId);
if (!$coroutine->isCompleted($taskId)) {
$futureThread = $callableTask->getCustomData();
- if ($futureThread instanceof FutureInterface || $futureThread instanceof Thread) {
+ if ($futureThread instanceof FutureInterface || $futureThread instanceof Thread || $futureThread instanceof TWorker) {
$callableTask->setCaller($task);
if ($futureThread instanceof FutureInterface) {
$delay = 1;
diff --git a/composer.json b/composer.json
index 1cff53d..7e44bd1 100644
--- a/composer.json
+++ b/composer.json
@@ -41,7 +41,8 @@
"php": ">7.1",
"psr/log": "^1.0.0",
"psr/container": ">2.0",
- "symplely/spawn": "^4.1.8"
+ "symplely/spawn": "^5.0.1",
+ "symplely/thread_queue": "main-dev"
},
"autoload": {
"files": [
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index ea9904f..854fb5d 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -11,6 +11,7 @@
tests/misc/
tests/network/
tests/
+ tests/thread/
diff --git a/tests/ZTSTestWorkerByThread.php b/tests/thread/WorkerByThreadTest.php
similarity index 98%
rename from tests/ZTSTestWorkerByThread.php
rename to tests/thread/WorkerByThreadTest.php
index 86615eb..b1b1c4c 100644
--- a/tests/ZTSTestWorkerByThread.php
+++ b/tests/thread/WorkerByThreadTest.php
@@ -32,7 +32,7 @@ function fib($n)
return fib(n - 1) + fib(n - 2)
*/
-class ZTSTestWorkerByThread extends TestCase
+class WorkerByThreadTest extends TestCase
{
/**
* @var Event