Skip to content

Commit

Permalink
Fix Swoole coroutine http server
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Oct 2, 2023
1 parent d714fcb commit 6c8ffb0
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/Http/Adapter/Swoole/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Swoole\Coroutine;
use Utopia\Http\Adapter;
use Swoole\Http\Server as SwooleServer;
use Swoole\Coroutine\Http\Server as SwooleServer;
use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse;

Expand All @@ -30,34 +30,19 @@ public function setConfig(array $configs)

public function onRequest(callable $callback)
{
$this->server->on('request', function (SwooleRequest $request, SwooleResponse $response) use ($callback) {
$this->server->handle('/', function (SwooleRequest $request, SwooleResponse $response) use ($callback) {
call_user_func($callback, new Request($request), new Response($response), \strval(Coroutine::getCid()));
});
}

public function onWorkerStart(callable $callback)
{
$this->server->on('WorkerStart', $callback);
}

public function onBeforeReload(callable $callback)
{
$this->server->on('BeforeReload', $callback);
}

public function onAfterReload(callable $callback)
{
$this->server->on('AfterReload', $callback);
}

public function onBeforeShutdown(callable $callback)
{
$this->server->on('beforeShutdown', $callback);
return;
}

public function onStart(callable $callback)
{
$this->server->on('start', $callback);
call_user_func($callback, $this);
}

public function start()
Expand Down

0 comments on commit 6c8ffb0

Please sign in to comment.