src/WebPush.php
public function flush(?int $batchSize = null): \Generator
    {
        if (null === $this->notifications || empty($this->notifications)) {
            yield from [];
            return;
        }

        if (null === $batchSize) {
            $batchSize = $this->defaultOptions['batchSize'];
        }

        $batches = array_chunk($this->notifications, $batchSize);

        // reset queue
        $this->notifications = [];

        foreach ($batches as $batch) {
            // for each endpoint server type
            $requests = $this->prepare($batch);

            $promises = [];

            foreach ($requests as $request) {
                $promises[] = $this->client->sendAsync($request)
                    ->then(function ($response) use ($request) {
                        /** @var ResponseInterface $response * */
                        return new MessageSentReport($request, $response);
                    })
                    ->otherwise(function ($reason) {
                        /** @var RequestException $reason **/
                        return new MessageSentReport($reason->getRequest(), $reason->getResponse(), false, $reason->getMessage());
                    });
            }

            foreach ($promises as $promise) {
                yield $promise->wait();
            }
        }

        if ($this->reuseVAPIDHeaders) {
            $this->vapidHeaders = [];
        }
    }
public function flush(?int $batchSize = null): \Generator
    {
        if (null === $this->notifications || empty($this->notifications)) {
            yield from [];
            return;
        }

        if (null === $batchSize) {
            $batchSize = $this->defaultOptions['batchSize'];
        }

        $batches = array_chunk($this->notifications, $batchSize);

        // reset queue
        $this->notifications = [];

        foreach ($batches as $batch) {
            // for each endpoint server type
            $requests = $this->prepare($batch);

            $promises = [];

            foreach ($requests as $request) {
                $promises[] = $this->client->sendAsync($request)
                    ->then(function ($response) use ($request) {
                        /** @var ResponseInterface $response * */
                        return new MessageSentReport($request, $response);
                    })
                    ->otherwise(function ($reason) {
                        /** @var RequestException $reason **/
                        return new MessageSentReport($reason->getRequest(), $reason->getResponse(), false, $reason->getMessage());
                    });
            }

            foreach ($promises as $promise) {
                yield $promise->wait();
            }
        }

        if ($this->reuseVAPIDHeaders) {
            $this->vapidHeaders = [];
        }
    }
public function flush ( ? int $ batchSize = null ) : \ Generator { if ( null === $ this -> notifications || empty ( $ this -> notifications ) ) { yield from [ ] ; return ; } if ( null === $ batchSize ) { $ batchSize = $ this -> defaultOptions [ 'batchSize' ] ; } $ batches = array_chunk ( $ this -> notifications , $ batchSize ) ; // reset queue $ this -> notifications = [ ] ; foreach ( $ batches as $ batch ) { // for each endpoint server type $ requests = $ this -> prepare ( $ batch ) ; $ promises = [ ] ; foreach ( $ requests as $ request ) { $ promises [ ] = $ this -> client -> sendAsync ( $ request ) -> then ( function ( $ response ) use ( $ request ) { /** @var ResponseInterface $response * */ return new MessageSentReport ( $ request , $ response ) ; } ) -> otherwise ( function ( $ reason ) { /** @var RequestException $reason **/ return new MessageSentReport ( $ reason -> getRequest ( ) , $ reason -> getResponse ( ) , false , $ reason -> getMessage ( ) ) ; } ) ; } foreach ( $ promises as $ promise ) { yield $ promise -> wait ( ) ; } } if ( $ this -> reuseVAPIDHeaders ) { $ this -> vapidHeaders = [ ] ; } }
Flush notifications. Triggers the requests.

@param null|int $batchSize Defaults the value defined in defaultOptions during instantiation (which defaults to 1000).

@return \Generator|MessageSentReport[]
@throws \ErrorException
Flush notifications . Triggers the requests .