protected function createResource(callable $callback)
    {
        $parameters = $this->parameters;
        $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT;

        if ($parameters->scheme === 'unix') {
            $uri = "unix://$parameters->path";
        } else {
            $uri = "$parameters->scheme://$parameters->host:$parameters->port";
        }

        if (!$stream = @stream_socket_client($uri, $errno, $errstr, 0, $flags)) {
            $this->onError(new ConnectionException($this, \trim($errstr), $errno));

            return;
        }

        \stream_set_blocking($stream, 0);

        $this->state->setState(State::CONNECTING);

        $this->loop->addWriteStream($stream, function ($stream) use ($callback) {
            if ($this->onConnect()) {
                \call_user_func($callback, $this);
                $this->write();
            }
        });

        $this->timeout = $this->armTimeoutMonitor(
            $parameters->timeout ?: 5, $this->errorCallback ?: function () { }
        );

        return $stream;
    }