You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve error reporting when incorrectly using await() (Value of type null is not callable in src/SimpleFiber.php:66) #50
How to fix it is known: wrap $foo into Async\async. But the error sucks anyway. You guys gotta find a way to get it either work anyway, or throw a nice error telling us what is wrong and hinting what to do.
Hey @greendrake
You're not wrong, the error message could be a bit more precise. If you already have some ideas we're always happy about pull requests. 👍
changed the title [-]Value of type null is not callable in src/SimpleFiber.php:66[/-][+]Improve error reporting when incorrectly using `await()` (Value of type null is not callable in src/SimpleFiber.php:66)[/+]on Jun 20, 2022
I am having the same error: Value of type null is not callable in src/SimpleFiber.phpreact/async/src/SimpleFiber.php:74.
Tried to do what @greendrake told: wrap into async but it does not work.
@WyriHaximus sure. I am testing my laravel-websockets functionality. Here's the code.
ConnectionTest.php
<?phpnamespaceModules\Lobby\Tests\Unit\Sockets;
class ConnectionTest extends SocketTestCase
{
publicfunctiontest_debugging_error()
{
$this->startServer(function () {
$this->connect("/app/INVALID-APP-KEY/room/INVALID-ROOM-ID", function () {
dump('connection #1');
$this->assertTrue(true);
});
});
$this->startServer(function () {
$this->connect("/app/INVALID-APP-KEY/room/INVALID-ROOM-ID", function () {
dump('connection #2');
$this->assertTrue(true);
});
});
dd('CONNECTION #1 IS OK. BUT SCRIPT FAILS CONNECTING #2 BECAUSE OF THE `await($promise)` ERROR: Value of type null is not callable in src/SimpleFiber.php IN react/async/src/SimpleFiber.php:74');
}
}
Method connect creates a promise of a Ratchet client and then awaits for the promise to be resolved.
Once resolved, the closure from the test method is called
the connection is immediately closed
await unblocks
the next connection test block starts
The error is triggered when called the next await function.
As far I debugged, the second time await runs, the variable $this->$scheduler is no more null in the SimpleFiber.php which is then called the start() assigning value of null to $ret.
Like I said above, the current error message is confusing and we want to give this a more meaningful content. @clue and I invested a few hours into a potential fix in the past, but we quickly ran into some overlaps with #65. It seems like we first need to file a new pull request in https://github.com/reactphp/event-loop in order to fix this here. We also have to define the expected behavior and write additional test cases.
Stopping the loop like you described in your example above doesn't really fix the problem here. Additionally, you shouldn't use $loop->stop() as described in https://github.com/reactphp/event-loop#stop:
This method is considered advanced usage and should be used with care. As a rule of thumb, it is usually recommended to let the loop stop only automatically when it no longer has anything to do.
We'll give an update once we filed the necessary pull requests and renamed this message to be more meaningful.
Activity
SimonFrings commentedon Jun 20, 2022
Hey @greendrake
You're not wrong, the error message could be a bit more precise. If you already have some ideas we're always happy about pull requests. 👍
[-]Value of type null is not callable in src/SimpleFiber.php:66[/-][+]Improve error reporting when incorrectly using `await()` (Value of type null is not callable in src/SimpleFiber.php:66)[/+]mowses commentedon Jul 21, 2023
I am having the same error:
Value of type null is not callable in src/SimpleFiber.phpreact/async/src/SimpleFiber.php:74.Tried to do what @greendrake told: wrap into
asyncbut it does not work.Does anyone have the solution code to share?
WyriHaximus commentedon Jul 21, 2023
@mowses can you share any code that triggers this?
mowses commentedon Jul 22, 2023
Update: right now I am reading your blog at https://blog.wyrihaximus.net/2021/12/async-and-await-at-the-edge-with-reactphp/
@WyriHaximus sure. I am testing my
laravel-websocketsfunctionality. Here's the code.ConnectionTest.phpSocketTestCase.phpMethod
connectcreates a promise of a Ratchet client and then awaits for the promise to be resolved.The error is triggered when called the next
awaitfunction.As far I debugged, the second time await runs, the variable
$this->$scheduleris no morenullin theSimpleFiber.phpwhich is then called thestart()assigning value ofnullto$ret.mowses commentedon Jul 26, 2023
I managed to handle my problem. For the people who had the same issue, here's what I did to solve:
Loopinstance and passed as the fourth parameter ofconnect()function;asyncfunction;$loop->run();$loop->stop();after the request was resolved/rejected;Here is the modified method:
SimonFrings commentedon Oct 24, 2023
@mowses Thanks for your input on this 👍
Like I said above, the current error message is confusing and we want to give this a more meaningful content. @clue and I invested a few hours into a potential fix in the past, but we quickly ran into some overlaps with #65. It seems like we first need to file a new pull request in https://github.com/reactphp/event-loop in order to fix this here. We also have to define the expected behavior and write additional test cases.
Stopping the loop like you described in your example above doesn't really fix the problem here. Additionally, you shouldn't use
$loop->stop()as described in https://github.com/reactphp/event-loop#stop:We'll give an update once we filed the necessary pull requests and renamed this message to be more meaningful.
mrAndersen commentedon Nov 7, 2024
I am getting the same error, now at assert() expression:
The code:
Thus this periodically throws Empty response because $response is NULL and when this happens I am getting:
reactphp/async is 4.3.0
mrAndersen commentedon Nov 7, 2024
Code:
Also produces