Last active
April 11, 2025 15:09
-
-
Save igalshilman/800b91db355126dcb5c31f4b8e4f3574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { service, type Context } from "@restatedev/restate-sdk"; | |
interface ServiceB { | |
greet: (ctx: Context, name: string) => Promise<string>; | |
} | |
const realServiceB = service({ | |
name: "realServiceB", | |
handlers: { | |
greet: async (ctx: Context, name: string) => { | |
return `Hello ${name}`; | |
}, | |
} satisfies ServiceB, | |
}); | |
const makeServiceA = (serviceB: ServiceB) => | |
service({ | |
name: "serviceA", | |
handlers: { | |
greet: async (ctx: Context, name: string) => { | |
const greeting = await serviceB.greet(ctx, name); | |
return `Hello ${greeting}`; | |
}, | |
}, | |
}); | |
const serviceA = makeServiceA({ | |
greet: (ctx: Context, name: string): Promise<string> => { | |
// | |
// you can mock the behavior however you want here, as if you are serviceB | |
// or you can even forward the call to service B (or the mock one) | |
// | |
return Promise.resolve(`a mock greeting for ${name}`); | |
}, | |
}); | |
const realServiceA = makeServiceA({ | |
greet: (ctx: Context, name: string): Promise<string> => | |
ctx.serviceClient<ServiceB>({ name: "realServiceB" }).greet(name), | |
}); |
Author
igalshilman
commented
Apr 11, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment