Skip to content

Commit

Permalink
get boned octane
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirewraith committed Dec 11, 2024
1 parent 6ac024f commit fe9f512
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions app/Libraries/GameBridge/BridgeConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,28 @@ public function cacheFor(int $seconds)

private function handler($address, $port, $options)
{
return function () use ($address, $port, $options) {
$socket = new BridgeConnectionSocket($address, $port, $options);
$response = '';
$error = false;

try {
$socket->send();
if ($socket->wantResponse) {
$response = $socket->read();
$error = $socket->error;
}
} catch (\Throwable $e) {
if ($socket->wantResponse) {
$response = $e->getMessage();
$error = true;
}
// return function () use ($address, $port, $options) {
$socket = new BridgeConnectionSocket($address, $port, $options);
$response = '';
$error = false;

try {
$socket->send();
if ($socket->wantResponse) {
$response = $socket->read();
$error = $socket->error;
}
} catch (\Throwable $e) {
if ($socket->wantResponse) {
$response = $e->getMessage();
$error = true;
}
}

$socket->disconnect();
$socket->disconnect();

return new BridgeConnectionResponse($response, $error, $socket->cacheHit);
};
return new BridgeConnectionResponse($response, $error, $socket->cacheHit);
// };
}

public function send(bool $wantResponse = true): BridgeConnectionResponse|Collection
Expand All @@ -132,26 +132,28 @@ public function send(bool $wantResponse = true): BridgeConnectionResponse|Collec
'wantResponse' => $wantResponse,
];

$jobs = [];
$timeout = 0;
// $jobs = [];
// $timeout = 0;
$responses = collect();
foreach ($this->targets as $target) {
$jobs[$target->serverId] = $this->handler($target->address, $target->port, $options);
if ($wantResponse) {
$timeout += $this->timeout * 3; // connect, send, read
} else {
$timeout += $this->timeout * 2; // connect, send
}
// $jobs[$target->serverId] = $this->handler($target->address, $target->port, $options);
// if ($wantResponse) {
// $timeout += $this->timeout * 3; // connect, send, read
// } else {
// $timeout += $this->timeout * 2; // connect, send
// }
$responses->add($this->handler($target->address, $target->port, $options));
}

$response = null;
try {
$responses = collect(Octane::concurrently($jobs, $timeout * 1000));
$response = count($responses) === 1 ? $responses->first() : $responses;
} catch (TaskTimeoutException $e) {
$response = new BridgeConnectionResponse($e->getMessage(), true);
}
// $response = null;
// try {
// $responses = collect(Octane::concurrently($jobs, $timeout * 1000));
// $response = count($responses) === 1 ? $responses->first() : $responses;
// } catch (TaskTimeoutException $e) {
// $response = new BridgeConnectionResponse($e->getMessage(), true);
// }

return $response;
return count($responses) === 1 ? $responses->first() : $responses;
}

public function sendAndForget()
Expand Down

0 comments on commit fe9f512

Please sign in to comment.