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
$connector = new \React\Socket\Connector(); that connect to server and listen.
I add handler to 'data' event.
// did not write to event.log
$connector = new \React\Socket\Connector();
$connector->connect($host)->then(function (\React\Socket\ConnectionInterface $connection) {
$connection->on('data', \React\Async\async(
function ($data) {
file_put_contents('/home/carsak/event.log', $data . PHP_EOL, FILE_APPEND);
}
));
});
function inside async did not invoked
but if I wrote without async function, function write logs into event.log file
// it works
$connector = new \React\Socket\Connector();
$connector->connect($host)->then(function (\React\Socket\ConnectionInterface $connection) {
$connection->on('data',
function ($data) {
file_put_contents('/home/bitrix/dialer/event.log', $data . PHP_EOL, FILE_APPEND);
}
);
});
I checked docs several times and read about
The async() function is specifically designed for cases where it is used as a callback (such as an event loop timer, event listener, or promise callback). For this reason, it returns a new function wrapping the given $function instead of directly invoking it and returning its value.
Hey @Carsak, you're currently using a blocking function (file_put_contents()) inside your async function. The async() function only works in tandem with the await() function and does not "magically" make any blocking function non-blocking. This is also described in the documentation for the async() function. So as long as you're not using the await() function, it doesn't make much sense to use async() here.
I believe this should answer your question, so I will close this ticket for now. We can reopen this if you encounter the same issues again after trying out the solutions mentioned in here. If you do need to reopen the ticket, please provide some information about the steps you've taken so far, what worked and what didn't.
FYI: I think this kind of ticket is better suited for a discussion in our "Q&A" section. We recommend opening bug tickets only when you can provide evidence of something being broken, just as a friendly reminder for future tickets :)
I have TCP client
$connector = new \React\Socket\Connector();
that connect to server and listen.I add handler to 'data' event.
function inside async did not invoked
but if I wrote without async function, function write logs into event.log file
I checked docs several times and read about
Follow the example
My composer.json
What I did wrong?
The text was updated successfully, but these errors were encountered: