Interface NewStreamOptions

An object that contains an AbortSignal as the optional signal property.

Example

const controller = new AbortController()

aLongRunningOperation({
signal: controller.signal
})

// later

controller.abort()
interface NewStreamOptions {
    maxOutboundStreams?: number;
    negotiateFully?: boolean;
    runOnLimitedConnection?: boolean;
    signal?: AbortSignal;
}

Hierarchy (view full)

Properties

maxOutboundStreams?: number

If specified, and no handler has been registered with the registrar for the successfully negotiated protocol, use this as the max outbound stream limit for the protocol

negotiateFully?: boolean

By default when negotiating a protocol the dialer writes then protocol name then reads the response.

When a only a single protocol is being negotiated on an outbound stream, and the stream is written to before being read from, we can optimistically write the protocol name and the first chunk of data together in the first message.

Reading and handling the protocol response is done asynchronously, which means we can skip a round trip on writing to newly opened streams which significantly reduces the time-to-first-byte on a stream.

The side-effect of this is that the underlying stream won't negotiate the protocol until either data is written to or read from the stream so it will not be opened on the remote until this is done.

Pass false here to optimistically write the protocol name and first chunk of data in the first message.

If multiple protocols are being negotiated, negotiation is always completed in full before the stream is returned so this option has no effect.

Default

true
runOnLimitedConnection?: boolean

Opt-in to running over a limited connection - one that has restrictions on the amount of data that may be transferred or how long it may be open for.

These limits are typically enforced by a relay server, if the protocol will be transferring a lot of data or the stream will be open for a long time consider upgrading to a direct connection before opening the stream.

Default

false
signal?: AbortSignal