@resonatehq/sdk
    Preparing search index...

    Class Resonate

    Index

    Constructors

    • Parameters

      • __namedParameters: {
            auth?: { password: string; username: string };
            group?: string;
            pid?: string;
            ttl?: number;
            url?: string;
        } = {}

      Returns Resonate

    Properties

    promises: Promises
    schedules: Schedules

    Methods

    • Initiates a remote procedure call (RPC) with Resonate and returns a handle to the execution.

      This method schedules a registered function for remote execution under a durable promise identified by the provided id. The function runs on a remote worker or process as part of Resonate’s distributed execution environment.

      Unlike rpc, this method is non-blocking and immediately returns a ResonateHandle that can be awaited or queried later to retrieve the final result once remote execution completes.

      If a durable promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed. Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior.

      Type Parameters

      • F extends Func

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent remote execution.

      • func: F
      • ...args: [...Params<F>[], Options?]

      Returns Promise<ResonateHandle<Return<F>>>

      A ResonateHandle representing the asynchronous remote execution. The handle can be awaited or inspected for completion and results.

      const handle = await client.beginRpc("task-123", "processData", { input: "hello" });
      const result = await handle.getResult();
      console.log(result);
    • Initiates a remote procedure call (RPC) with Resonate and returns a handle to the execution.

      This method schedules a registered function for remote execution under a durable promise identified by the provided id. The function runs on a remote worker or process as part of Resonate’s distributed execution environment.

      Unlike rpc, this method is non-blocking and immediately returns a ResonateHandle that can be awaited or queried later to retrieve the final result once remote execution completes.

      If a durable promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed. Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior.

      Type Parameters

      • T

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent remote execution.

      • func: string
      • ...args: any[]

      Returns Promise<ResonateHandle<T>>

      A ResonateHandle representing the asynchronous remote execution. The handle can be awaited or inspected for completion and results.

      const handle = await client.beginRpc("task-123", "processData", { input: "hello" });
      const result = await handle.getResult();
      console.log(result);
    • Initiates a remote procedure call (RPC) with Resonate and returns a handle to the execution.

      This method schedules a registered function for remote execution under a durable promise identified by the provided id. The function runs on a remote worker or process as part of Resonate’s distributed execution environment.

      Unlike rpc, this method is non-blocking and immediately returns a ResonateHandle that can be awaited or queried later to retrieve the final result once remote execution completes.

      If a durable promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed. Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior.

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent remote execution.

      • funcOrName: string | Func

        Either the registered function reference or its string name to execute remotely.

      • ...args: any[]

      Returns Promise<ResonateHandle<any>>

      A ResonateHandle representing the asynchronous remote execution. The handle can be awaited or inspected for completion and results.

      const handle = await client.beginRpc("task-123", "processData", { input: "hello" });
      const result = await handle.getResult();
      console.log(result);
    • Runs a registered function asynchronously with Resonate.

      This method schedules the specified function for execution under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Unlike run, this method is non-blocking and immediately returns a ResonateHandle that can be awaited or queried later to retrieve the final result once execution completes.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      Type Parameters

      • F extends Func

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent execution.

      • func: F
      • ...args: [...Params<F>[], Options?]

      Returns Promise<ResonateHandle<Return<F>>>

      A ResonateHandle representing the asynchronous execution. The handle can be awaited or inspected for status and results.

      const handle = await client.beginRun("run-001", "generateReport", { period: "Q3" });
      const result = await handle.getResult();
      console.log(result);
    • Runs a registered function asynchronously with Resonate.

      This method schedules the specified function for execution under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Unlike run, this method is non-blocking and immediately returns a ResonateHandle that can be awaited or queried later to retrieve the final result once execution completes.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      Type Parameters

      • T

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent execution.

      • func: string
      • ...args: any[]

      Returns Promise<ResonateHandle<T>>

      A ResonateHandle representing the asynchronous execution. The handle can be awaited or inspected for status and results.

      const handle = await client.beginRun("run-001", "generateReport", { period: "Q3" });
      const result = await handle.getResult();
      console.log(result);
    • Runs a registered function asynchronously with Resonate.

      This method schedules the specified function for execution under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Unlike run, this method is non-blocking and immediately returns a ResonateHandle that can be awaited or queried later to retrieve the final result once execution completes.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent execution.

      • funcOrName: string | Func

        Either the registered function reference or its string name to execute.

      • ...args: any[]

      Returns Promise<ResonateHandle<any>>

      A ResonateHandle representing the asynchronous execution. The handle can be awaited or inspected for status and results.

      const handle = await client.beginRun("run-001", "generateReport", { period: "Q3" });
      const result = await handle.getResult();
      console.log(result);
    • Retrieves or subscribes to an existing execution by its unique ID.

      This method attaches to an existing durable promise identified by id. If the associated execution is still in progress, it returns a ResonateHandle that can be awaited or observed until completion. If the execution has already finished, the handle is immediately resolved with the stored result.

      Notes:

      • A durable promise with the given id must already exist.
      • This operation is non-blocking; awaiting the returned handle will block only if the execution is still running.

      Type Parameters

      • T = any

      Parameters

      • id: string

        Unique identifier of the target execution or durable promise.

      Returns Promise<ResonateHandle<T>>

      A ResonateHandle representing the existing execution. The handle can be awaited or queried to retrieve the final result.

    • Registers a function with Resonate for execution and version control.

      This method makes a function available for distributed or top-level execution under a specific name and version.

      Providing explicit name or version options allows precise control over function identification and versioning, enabling repeatable, distributed invocation and backward-compatible deployments.

      Type Parameters

      • F extends Func

      Parameters

      • name: string
      • func: F
      • Optionaloptions: { version?: number }

      Returns ResonateFunc<F>

      A ResonateFunc wrapper for the registered function. When used as a decorator, returns a decorator that registers the target function upon definition.

      function greet(ctx: Context, name: string): string {
      return `Hello, ${name}!`;
      }

      resonate.register("greet_user", greet, { version: 2 });
    • Registers a function with Resonate for execution and version control.

      This method makes a function available for distributed or top-level execution under a specific name and version.

      Providing explicit name or version options allows precise control over function identification and versioning, enabling repeatable, distributed invocation and backward-compatible deployments.

      Type Parameters

      • F extends Func

      Parameters

      • func: F
      • Optionaloptions: { version?: number }

      Returns ResonateFunc<F>

      A ResonateFunc wrapper for the registered function. When used as a decorator, returns a decorator that registers the target function upon definition.

      function greet(ctx: Context, name: string): string {
      return `Hello, ${name}!`;
      }

      resonate.register("greet_user", greet, { version: 2 });
    • Executes a registered function remotely with Resonate and waits for the result.

      This method runs the specified function on a remote worker or process under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Unlike beginRpc, this method is blocking — it waits for the remote function to complete and returns the final result before continuing execution.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      Type Parameters

      • F extends Func

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent remote execution.

      • func: F
      • ...args: [...Params<F>[], Options?]

        Positional arguments passed to the remote function.

      Returns Promise<Return<F>>

      A promise resolving to the final result returned from the remote function execution.

      const result = await client.rpc("job-42", "analyzeData", { file: "input.csv" });
      console.log("Remote result:", result);
    • Executes a registered function remotely with Resonate and waits for the result.

      This method runs the specified function on a remote worker or process under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Unlike beginRpc, this method is blocking — it waits for the remote function to complete and returns the final result before continuing execution.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      Type Parameters

      • T

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent remote execution.

      • name: string
      • ...args: any[]

        Positional arguments passed to the remote function.

      Returns Promise<T>

      A promise resolving to the final result returned from the remote function execution.

      const result = await client.rpc("job-42", "analyzeData", { file: "input.csv" });
      console.log("Remote result:", result);
    • Executes a registered function remotely with Resonate and waits for the result.

      This method runs the specified function on a remote worker or process under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Unlike beginRpc, this method is blocking — it waits for the remote function to complete and returns the final result before continuing execution.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      Type Parameters

      • T

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent remote execution.

      • funcOrName: string | Func

        Either the registered function reference or its string name to execute remotely.

      • ...args: any[]

        Positional arguments passed to the remote function.

      Returns Promise<T>

      A promise resolving to the final result returned from the remote function execution.

      const result = await client.rpc("job-42", "analyzeData", { file: "input.csv" });
      console.log("Remote result:", result);
    • Runs a registered function with Resonate and waits for the result.

      This method executes the specified function under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      This is a blocking operation — execution will not continue until the function result is available.

      Type Parameters

      • F extends Func

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent execution.

      • func: F
      • ...args: [...Params<F>[], Options?]

        Positional arguments passed to the function.

      Returns Promise<Return<F>>

      A promise resolving to the final result returned from the function execution.

      const result = await client.run("job-123", "processData", { input: "records.csv" });
      console.log("Result:", result);
    • Runs a registered function with Resonate and waits for the result.

      This method executes the specified function under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      This is a blocking operation — execution will not continue until the function result is available.

      Type Parameters

      • T

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent execution.

      • name: string
      • ...args: any[]

        Positional arguments passed to the function.

      Returns Promise<T>

      A promise resolving to the final result returned from the function execution.

      const result = await client.run("job-123", "processData", { input: "records.csv" });
      console.log("Result:", result);
    • Runs a registered function with Resonate and waits for the result.

      This method executes the specified function under a durable promise identified by the provided id. If a promise with the same id already exists, Resonate subscribes to its result or returns it immediately if it has already completed.

      Duplicate executions for the same id are automatically prevented, ensuring idempotent and consistent behavior across distributed runs.

      This is a blocking operation — execution will not continue until the function result is available.

      Type Parameters

      • T

      Parameters

      • id: string

        The unique identifier of the durable promise. Reusing an ID ensures idempotent execution.

      • funcOrName: string | Func

        Either the registered function reference or its string name to execute.

      • ...args: any[]

        Positional arguments passed to the function.

      Returns Promise<T>

      A promise resolving to the final result returned from the function execution.

      const result = await client.run("job-123", "processData", { input: "records.csv" });
      console.log("Result:", result);
    • Type Parameters

      • F extends Func

      Parameters

      • name: string
      • cron: string
      • func: F
      • ...args: [...Params<F>[], Options?]

      Returns Promise<ResonateSchedule>

    • Parameters

      • name: string
      • cron: string
      • func: string
      • ...args: any[]

      Returns Promise<ResonateSchedule>

    • Parameters

      • name: string
      • obj: any

      Returns void

    • Initializes a Resonate client instance for local development.

      Creates and returns a Resonate client configured for local-only execution with zero external dependencies. All state is stored in local memory — no network or external persistence is required. This mode is ideal for rapid testing, debugging, and experimentation before connecting to a Resonate server.

      The client runs with a "default" worker group, a "default" process ID, and an effectively infinite TTL (Number.MAX_SAFE_INTEGER) for tasks.

      Returns Resonate

      A Resonate client instance configured for local development.

      const resonate = Resonate.local();
      resonate.register(foo);
      const result = await resonate.run("foo.1", foo, { data: "test" });
      console.log(result);
    • Initializes a Resonate client instance with remote configuration.

      Creates and returns a Resonate client that connects to a Resonate Server and optional remote message sources. This configuration enables distributed, durable workers to cooperate and execute functions via durable RPCs.

      By default, the client connects to a Resonate Server running locally (http://localhost:8001) and joins the "default" worker group.

      The client is identified by a unique process ID (pid) and maintains claimed task leases for the duration specified by ttl.

      Parameters

      • options: {
            auth?: { password: string; username: string };
            group?: string;
            messageSourceAuth?: { password: string; username: string };
            pid?: string;
            ttl?: number;
            url?: string;
        } = {}

        Configuration options for the remote client.

        • Optionalauth?: { password: string; username: string }

          Optional authentication credentials for connecting to the remote server.

        • Optionalgroup?: string

          The worker group name. Defaults to "default".

        • OptionalmessageSourceAuth?: { password: string; username: string }
        • Optionalpid?: string

          Optional process identifier for the client. Defaults to a randomly generated UUID.

        • Optionalttl?: number

          Time-to-live (in seconds) for claimed tasks. Defaults to 1 * util.MIN.

        • Optionalurl?: string

          The base URL of the remote Resonate Server. Defaults to "http://localhost:8001".

      Returns Resonate

      A Resonate client instance configured for remote operation.

      const resonate = Resonate.remote({
      url: "https://resonate.example.com",
      group: "analytics",
      ttl: 30,
      auth: { username: "user", password: "secret" },
      });

      const result = await resonate.run("task-42", "processData", { input: "dataset.csv" });
      console.log(result);