Skip to content

Abortable pollable promises and invocations #2528

@vigoo

Description

@vigoo

Currently we cannot race invocations in TypeScript agents because there is no way to abort the invocation promises after getting a winner out of the race. As the other invocation promises remain registered in the runtime, the whole invocation (the caller agent) will not finish until all of these promises also finish.

To solve this, we need the following steps:

  • in wasm-rquickjs, we generate a promise() method for the WASI Pollable resource, which under the hood uses wstd to await the promise in an asynchronous way. We need an abortablePromise(signal: AbortSignal) variant of this, but it is not clear how to implement this on the wstd/rust futures level. Most likely requires polling the signal on top of monotonic clock subscriptions.
  • In the TypeScript SDK, we can add an abortable variant to the RPC methods (similar to the current trigger and schedule) that takes an AbortSignal
  • Optionally the abortion of an invocation could also try using the cancel pending invocation API to remove an invoke from the agent's pending queue if it has not been started yet.

Note the goal is not to prevent the remove agent to do the invoked method, just to prevent the JS runtime from waiting for it.

With direct support for AbortSignal invocations can be cancellable promises and races done conveniently for exampel with Effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions