Skip to content

Commit d17655b

Browse files
Context interface rework (#257)
* Merge Handler API/Grpc API context interfaces into Context. * Split Context to Context/KeyedContext to distinguish which has access to state.
1 parent 5a69ec6 commit d17655b

28 files changed

+453
-402
lines changed

examples/example.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as restate from "../src/public_api";
2222
// The main entry point for the service, receiving the greeting request and name.
2323
//
2424
const greeter = restate.router({
25-
greet: async (ctx: restate.RpcContext, name: string) => {
25+
greet: async (ctx: restate.Context, name: string) => {
2626
// blocking RPC call to a keyed service (here supplying type and path separately)
2727
const countSoFar = await ctx
2828
.rpc<counterApiType>({ path: "counter" })
@@ -37,7 +37,7 @@ const greeter = restate.router({
3737
return message;
3838
},
3939

40-
logger: async (ctx: restate.RpcContext, msg: string) => {
40+
logger: async (ctx: restate.Context, msg: string) => {
4141
ctx.console.log(" HEEEELLLLOOOOO! " + msg);
4242
},
4343
});
@@ -48,7 +48,7 @@ const greeter = restate.router({
4848
// them here to have this multi-service setup for testing.
4949
//
5050
const counter = restate.keyedRouter({
51-
count: async (ctx: restate.RpcContext): Promise<number> => {
51+
count: async (ctx: restate.KeyedContext): Promise<number> => {
5252
const seen = (await ctx.get<number>("seen")) ?? 0;
5353
ctx.set("seen", seen + 1);
5454
return seen;

examples/grpc_example.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
*/
3131
export class GreeterService implements TestGreeter {
3232
async greet(request: TestRequest): Promise<TestResponse> {
33-
const ctx = restate.useContext(this);
33+
const ctx = restate.useKeyedContext(this);
3434

3535
// state
3636
let seen = (await ctx.get<number>("seen")) ?? 0;

0 commit comments

Comments
 (0)