Skip to content

Commit f4ce8a4

Browse files
committed
feat: adding Coroutine server
1 parent 1397674 commit f4ce8a4

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/Http/Adapter/SwooleCoroutine/Server.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
use Utopia\Http\Adapter;
66
use Swoole\Coroutine\Http\Server as SwooleServer;
77

8-
use function Swoole\Coroutine\run;
9-
108
class Server extends Adapter
119
{
1210
protected SwooleServer $server;
1311

1412
public function __construct(string $host, string $port = null, array $settings = [])
1513
{
16-
$this->server = new SwooleServer($host, $port);
14+
$this->server = new SwooleServer($host, $port, false, true);
1715
$this->server->set(\array_merge($settings, [
1816
'enable_coroutine' => true
1917
]));
@@ -22,15 +20,15 @@ public function __construct(string $host, string $port = null, array $settings =
2220
public function onRequest(callable $callback)
2321
{
2422
$this->server->handle('/', function ($request, $response) use ($callback) {
25-
call_user_func($callback, new Request($request), new Response($response));
23+
go(function () use ($request, $response, $callback) {
24+
call_user_func($callback, new Request($request), new Response($response));
25+
});
2626
});
2727
}
2828

2929
public function onStart(callable $callback)
3030
{
31-
go(function () use ($callback) {
32-
call_user_func($callback, $this);
33-
});
31+
call_user_func($callback, $this);
3432
}
3533

3634
public function start()

src/Http/Http.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,7 @@ public function start()
335335
clone $dependency
336336
->setName('http')
337337
->setCallback(fn () => $this)
338-
)
339-
->set(
340-
clone $dependency
341-
->setName('context')
342-
->setCallback(fn () => $context)
343-
)
344-
;
338+
);
345339

346340
$this->run($context);
347341
});

0 commit comments

Comments
 (0)