const counter = object({
name: "counter",
handlers: {
add: async (ctx: ObjectContext, amount: number) => {},
get: async (ctx: ObjectContext) => {}
}
})
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");
})
}
});
Define a Restate virtual object.