• Version 1.0.1
  • Published
  • 34.8 kB
  • 1 dependency
  • MIT license


npm i stagehand
yarn add stagehand
pnpm add stagehand


A type-safe library for communicating between JS processes, workers, or other message-passing boundaries.






    function connect

    connect: <T>(endpoint: MessageEndpoint) => Promise<Remote<T>>;
    • Given a message endpoint (and typically an explicit type parameter indicating the interface of the remote implementation), returns a promise that will resolve when successfully connected to the implementation on the other side of that endpoint.

      The resulting object will have methods defined on it that correspond to those of the backing implementation, returning a promise for the eventual result of that method.

    function disconnect

    disconnect: <T>(remote: Remote<T>) => void;
    • Given a remote object (as returned from connect), disconnects from the source and closes the connection.

    function launch

    launch: <T>(
    endpoint: MessageEndpoint,
    implementation: Implementation<T>
    ) => Promise<Stagehand<T>>;
    • Given a message endpoint and a backing implementation object, listens for a connection on the given endpoint and responds to commands that come in over it. This function will typically be called in whatever secondary thread/process will be servicing commands from the primary.


    interface MessageEndpoint

    interface MessageEndpoint {}
    • The minimal interface needed for stagehand communication. The adapters directory contains utilities for converting common types (e.g. Node's ChildProcess or the Web's MessagePort) into MessageEndpoints.

    method disconnect

    disconnect: () => void;

      method onMessage

      onMessage: (callback: (message: unknown) => void) => void;

        method sendMessage

        sendMessage: (message: unknown) => void;

          Type Aliases

          type Implementation

          type Implementation<T> = HandlerType<T>;
          • The necessarily implementation type of an intended remote interface T. All methods in Implementation<T> are allowed to return promises even if the corresponding method in T does not, but Implementation<T> also requires that all incoming callbacks be async, since they correspond to a remote type themselves.

          type Remote

          type Remote<T> = RemoteType<MethodsOnly<T>> & {
          [STAGEHAND_INSTANCE]: Stagehand<T>;
          • The remote implementation of a type T. It only includes Ts methods, and the return values of those methods are all made async if they weren't already.

          Package Files (1)

          Dependencies (1)

          Dev Dependencies (13)

          Peer Dependencies (0)

          No peer dependencies.


          To add a badge like this badgeto your package's README, use the codes available below.

          You may also use to create a custom badge linking to

          • Markdown
          • HTML
            <a href=""><img src="" alt=""></a>