Skip to content

Commit

Permalink
Support async for php > 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Aug 17, 2023
1 parent c3cfa6f commit a874c45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"phpseclib/phpseclib": "~2.0.30",
"ext-mbstring": "*",
"react/http": "^1.6.0",
"react/async": "^4.0.0",
"react/async": "^4.0.0|^3.1.0",
"react/promise": "^2.9.0",
"react/event-loop": "^1.2",
"react/socket": "^1.13"
Expand Down
11 changes: 8 additions & 3 deletions src/RequestManagers/HttpAsyncRequestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public function sendPayload($payload, $callback)
}

$host = $this->host;

return Async\coroutine(Async\async(function () use ($host, $payload, $callback) {
$request = function () use ($host, $payload, $callback) {
try {
$headers = [
'content-type' => 'application/json'
Expand Down Expand Up @@ -115,6 +114,12 @@ public function sendPayload($payload, $callback)
} catch (Exception $err) {
call_user_func($callback, $err, null);
}
}));
};

if (function_exists('React\\Async\\async')) {
$request = Async\async($request);
}

return Async\coroutine($request);
}
}

0 comments on commit a874c45

Please sign in to comment.