src/Datagram/BasicDatagram.php
private function createPoll($resource, \SplQueue $readQueue): Io
    {
        $length = &$this->length;

        return Loop\poll($resource, static function ($resource, bool $expired) use (&$length, $readQueue) {
            /** @var \Icicle\Awaitable\Delayed $delayed */
            $delayed = $readQueue->shift();

            try {
                if ($expired) {
                    throw new TimeoutException('The datagram timed out.');
                }

                $data = stream_socket_recvfrom($resource, $length, 0, $peer);

                // Having difficulty finding a test to cover this scenario, but the check seems appropriate.
                if (false === $data) { // Reading failed, so close datagram.
                    $message = 'Failed to read from datagram.';
                    if ($error = error_get_last()) {
                        $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
                    }
                    throw new FailureException($message);
                }

                list($address, $port) = Socket\parseName($peer);

                $result = [$address, $port, $data];

                $delayed->resolve($result);
            } catch (Throwable $exception) {
                $delayed->reject($exception);
            }
        });
    }
private function createPoll($resource, \SplQueue $readQueue): Io
    {
        $length = &$this->length;

        return Loop\poll($resource, static function ($resource, bool $expired) use (&$length, $readQueue) {
            /** @var \Icicle\Awaitable\Delayed $delayed */
            $delayed = $readQueue->shift();

            try {
                if ($expired) {
                    throw new TimeoutException('The datagram timed out.');
                }

                $data = stream_socket_recvfrom($resource, $length, 0, $peer);

                // Having difficulty finding a test to cover this scenario, but the check seems appropriate.
                if (false === $data) { // Reading failed, so close datagram.
                    $message = 'Failed to read from datagram.';
                    if ($error = error_get_last()) {
                        $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
                    }
                    throw new FailureException($message);
                }

                list($address, $port) = Socket\parseName($peer);

                $result = [$address, $port, $data];

                $delayed->resolve($result);
            } catch (Throwable $exception) {
                $delayed->reject($exception);
            }
        });
    }
@param resource $resource
@param \SplQueue $readQueue

@return \Icicle\Loop\Watcher\Io