winccoa-manager
    Preparing search index...

    Interface ServerContext

    Interface representing the context of a server-side call.

    interface ServerContext {
        onCanceled?: () => void;
        get cancelSignal(): AbortSignal;
        get deadline(): null | Date;
        get isCanceled(): boolean;
        get requestHeaders(): Vrpc.Metadata;
        get responseHeaders(): Vrpc.Metadata;
        get trailingHeaders(): Vrpc.Metadata;
        addResponseHeader(
            key: string,
            value: string | Buffer<ArrayBufferLike>,
        ): void;
        addTrailingHeader(
            key: string,
            value: string | Buffer<ArrayBufferLike>,
        ): void;
        getDeadlineAsMsSinceEpoch(): null | number;
        tryCancel(): void;
    }
    Index

    Properties

    onCanceled?: () => void

    A callback to be called when the server call is canceled.

    Accessors

    • get cancelSignal(): AbortSignal

      An AbortSignal. The abort event is invoked when the method got canceled.

      Returns AbortSignal

    • get deadline(): null | Date

      The deadline for the server call. Represents the time by which the server call must be completed. Returns null if no deadline is set.

      Returns null | Date

    • get isCanceled(): boolean

      Returns whether this RPC failed before the server could provide its status to the client.

      Returns boolean

      true if the RPC was canceled, otherwise false.

      This may be due to an explicit API rejection from the client or server-side or due to the deadline being exceeded. It does NOT include errors due to a non-OK status return by the server application's request handler, including Status::CANCELED.

    • get requestHeaders(): Vrpc.Metadata

      The header key-value pairs sent from the client.

      Returns Vrpc.Metadata

      Note that keys may appear more than once. It is safe to use this method after headers has been received. Calls always start with the client sending headers so that access to this data is safe as soon as the call has started on the server side.

    Methods

    • Adds a key-value pair to the headers associated with a server response call.

      Parameters

      • key: string

        The key for the header. If it is a binary value, it must end with "-bin". If it is an ASCII value, it must not end with "-bin".

      • value: string | Buffer<ArrayBufferLike>

        The value for the header, which can be a string or a Buffer.

      Returns void

      This method must only be called before sending response headers to the client. Which can happen explicitly, or implicitly when sending a response message or status to the client.

    • Adds a key-value pair to the trailing headers associated with a server call.

      Parameters

      • key: string

        The key for the headers.

      • value: string | Buffer<ArrayBufferLike>

        The value for the headers, which can be a string or a Buffer.

      Returns void

      This method must only be called before sending trailing headers to the client. Which happens when the call is finished and a status is sent to the client.

    • Gets the deadline for the client call as a number representing ms since the epoch.

      Returns null | number

      The deadline as a Date object, or null if no deadline is set.

    • Cancel the Call from the server.

      Returns void

      This is a best-effort API and depending on when it is called, the RPC may still appear successful to the client. For example, if tryCancel() is called on a separate thread, it might race with the server handler which might return success to the client before tryCancel() was even started by the thread.

      It is the caller's responsibility to prevent such races and ensure that if tryCancel() is called, the service implementation must return Status::CANCELED. The only exception is that if the service implementation is already returning an error status code, it is ok to not return Status::CANCELED even if tryCancel() was called.

      For reasons such as the above, it is generally preferred to explicitly finish an RPC by returning Status::CANCELED rather then using tryCancel.