This commit is contained in:
2021-01-04 18:40:11 +08:00
parent b4f6d1be35
commit 0c7a777ab4
3 changed files with 148 additions and 98 deletions
+22
View File
@@ -6,6 +6,7 @@ namespace Snowflake\Abstracts;
use Exception;
use HttpServer\Http\Context;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
@@ -99,6 +100,27 @@ abstract class Pool extends Component
throw new Exception('Undefined system processing function.');
}
/**
* @param array $config
* @param string $coroutineName
* @param callable $createHandler
*/
public function createConnect(array $config, string $coroutineName, callable $createHandler): void
{
if (Context::hasContext('create:connect:' . $coroutineName)) {
return;
}
Context::setContext('create:connect:' . $coroutineName, 1);
$client = call_user_func($createHandler, ...$config);
$this->push($coroutineName, $client);
Context::deleteId('create:connect:' . $coroutineName);
}
/**
* @param $name
* @return bool