Documentation
    Preparing search index...
    • Define a Restate virtual object.

      Type Parameters

      • P extends string
      • M

      Parameters

      • object: {
            description?: string;
            handlers: ObjectOpts<M> & ThisType<M>;
            metadata?: Record<string, string>;
            name: P;
            options?: ObjectOptions;
        }

      Returns VirtualObjectDefinition<P, M>

             const counter = object({
      name: "counter",
      handlers: {
      add: async (ctx: ObjectContext, amount: number) => {},
      get: async (ctx: ObjectContext) => {}
      }
      })
      ...
      endpoint.bind(counter)

      to interact with the object, you can use the object client:

      ...
      const client = ctx.objectClient<typeof counter>({ name: "counter"});
      const res = await client.add(1)

      Shared handlers are used to allow concurrent read-only access to the object. This is useful when you want to allow multiple clients to read the object's state at the same time. To define a shared handler, you can use the shared decorator as shown below:

           const counter = object({
      name: "counter",
      handlers: {

      add: async (ctx: ObjectContext, amount: number) => { .. },

      get: handlers.object.shared(async (ctx: ObjectSharedContext) => {
      return ctx.get<number>("count");
      })
      }
      });