Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 1, 2024
1 parent c2bff90 commit 91b7b8d
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 346 deletions.
36 changes: 0 additions & 36 deletions src/CoroutineServerInterface.php

This file was deleted.

68 changes: 0 additions & 68 deletions src/CoroutineServerMethods.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/CoroutineWebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function onConnect($connection, ...$params): void
call_user_func($call, $connection, ...$params);
});
}
if (!$this->_connectionChannels[$id = spl_object_hash($connection)] ?? null) {
if (!($this->_connectionChannels[$id = spl_object_hash($connection)] ?? null)) {
$this->_connectionChannels[$id] = new Channel(\config('plugin.workbunny.webman-coroutine.app.channel_size', 1));
}
}
Expand Down
33 changes: 0 additions & 33 deletions src/CoroutineWorkerInterface.php

This file was deleted.

61 changes: 0 additions & 61 deletions src/CoroutineWorkerMethods.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Workbunny\WebmanCoroutine;

use Webman\Http\Request;
use Workbunny\WebmanCoroutine\Events\SwooleEvent;
use Workbunny\WebmanCoroutine\Events\SwowEvent;
use Workbunny\WebmanCoroutine\Handlers\DefaultHandler;
Expand All @@ -17,8 +16,6 @@
use Workbunny\WebmanCoroutine\Handlers\SwooleWorkerman5Handler;
use Workbunny\WebmanCoroutine\Handlers\SwowHandler;
use Workbunny\WebmanCoroutine\Handlers\SwowWorkerman5Handler;
use Workerman\Connection\ConnectionInterface;
use Workerman\Worker;

/**
* 工厂化启动器
Expand Down Expand Up @@ -181,41 +178,4 @@ public static function init(?string $eventLoopClass): void
);
}
}

/**
* 根据当前环境运行处理器
*
* @param CoroutineServerInterface $app 实现CoroutineServerInterface
* @param mixed|ConnectionInterface $connection 连接资源
* @param mixed|Request $request 请求体
* @param string|null $eventLoopClass null:根据环境获取事件循环类
* @return mixed
*/
public static function run(CoroutineServerInterface $app, mixed $connection, mixed $request, ?string $eventLoopClass = null): mixed
{
self::init($eventLoopClass);
// 获取当前处理器
/** @var HandlerInterface $handlerClass */
$handlerClass = self::getCurrentHandler();

return $handlerClass::onMessage($app, $connection, $request);
}

/**
* 根据当前环境运行处理器
*
* @param CoroutineWorkerInterface $app 实现CoroutineWorkerInterface
* @param mixed|Worker|null $worker worker对象
* @param string|null $eventLoopClass null:根据环境获取事件循环类
* @return mixed
*/
public static function start(CoroutineWorkerInterface $app, mixed $worker = null, ?string $eventLoopClass = null): mixed
{
self::init($eventLoopClass);
// 获取当前处理器
/** @var HandlerInterface $handlerClass */
$handlerClass = self::getCurrentHandler();

return $handlerClass::onWorkerStart($app, $worker);
}
}
18 changes: 6 additions & 12 deletions src/Utils/Channel/Handlers/DefaultChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public function __destruct()

public function pop(int $timeout = -1): mixed
{
if ($this->_queue) {
return $this->_queue->dequeue();
}
return false;
return $this->_queue->dequeue();
}

/** @inheritdoc
Expand All @@ -43,29 +40,26 @@ public function pop(int $timeout = -1): mixed
*/
public function push(mixed $data, int $timeout = -1): bool
{
if ($this->_queue) {
$this->_queue->enqueue($data);
return true;
}
return false;
$this->_queue->enqueue($data);
return true;
}

/** @inheritdoc */
public function isEmpty(): bool
{
return $this->_queue?->isEmpty() ?: true;
return $this->_queue->isEmpty();
}

/** @inheritdoc */
public function isFull(): bool
{
return !($this->_capacity < 0) && $this->_capacity <= intval($this->_queue?->count());
return !($this->capacity() < 0) && $this->capacity() <= intval($this->_queue?->count());
}

/** @inheritdoc */
public function close(): void
{
$this->_queue = null;
$this->_queue = new \SplQueue();
}

/** @inheritdoc */
Expand Down
Loading

0 comments on commit 91b7b8d

Please sign in to comment.