Skip to content

Commit

Permalink
use promises
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Nov 30, 2023
1 parent 67639ed commit dd70f4e
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Laravel\Reverb\Contracts\ChannelConnectionManager;
use Laravel\Reverb\Contracts\Connection;
use React\EventLoop\Loop;
use Spatie\Fork\Fork;
use React\Promise\Promise;

class Channel
{
Expand Down Expand Up @@ -106,31 +105,15 @@ public function broadcastToAll(array $payload): void
{
$message = json_encode($payload);

$chunks = array_chunk($this->connections(), 5000);

$loop = Loop::get();
$chunks = array_chunk($this->connections(), 1000);

foreach ($chunks as $connections) {
$loop->futureTick(function () use ($connections, $message) {
new Promise(function ($resolve) use ($connections, $message) {
foreach ($connections as $connection) {
dump('Sending');
$connection->send($message);
}
});
}

// $forks = array_map(function ($connections) use ($message) {
// return function () use ($connections, $message) {
// foreach ($connections as $connection) {
// dump('Sending');
// $connection->send($message);
// }
// };
// }, $chunks);

// dump($forks);

// (new Fork)->run(...$forks);
}

/**
Expand Down

0 comments on commit dd70f4e

Please sign in to comment.