Skip to content

Feature: Add ability to get next events #33

Description

@mingfang

I'm trying to implement the ability to get the next set of possible events given the current state, as described here
https://stately.ai/docs/migration#statenextevents-has-been-removed

I tried adding a nextEvents handler here

like this and it seems to work.

      nextEvents: async (
        ctx: restate.ObjectContext<State>,
      ): Promise<string[]> => {
        await validateStateMachineIsNotDisposed(ctx);
        const systemName = ctx.key;

        // no need to set the version here if we are just getting a snapshot
        let version = await ctx.get("version");
        if (version == null) {
          version = latestLogic.id;
        }
        const logic = getLogic(latestLogic, versions, version);

        const root = await createActor<
          LatestStateMachine | PreviousStateMachine
        >(ctx, api, systemName, version, logic);

        const snapshot = root.getSnapshot();
        return [...new Set([...snapshot._nodes.flatMap((sn) => sn.ownEvents)])];
      },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions