Skip to content

Commit

Permalink
feat: Add nested tea brewer service to TypeScript coffee machine serv…
Browse files Browse the repository at this point in the history
…er example

Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
  • Loading branch information
pojntfx committed Sep 20, 2024
1 parent 160ced3 commit 5fb705b
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions ts/bin/panrpc-example-websocket-coffee-server-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,36 @@ import {
remoteClosure,
} from "../index";

class CoffeeMachine {
class TeaBrewer {
#supportedVariants: string[];

constructor(supportedVariants: string[]) {
this.#supportedVariants = supportedVariants;

this.GetVariants = this.GetVariants.bind(this);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async GetVariants(ctx: ILocalContext): Promise<string[]> {
return this.#supportedVariants;
}
}

class CoffeeMachine<E> {
public forRemotes?: (
cb: (remoteID: string, remote: RemoteControl) => Promise<void>
) => Promise<void>;

#supportedVariants: string[];

#waterLevel: number;

constructor(private supportedVariants: string[], waterLevel: number) {
constructor(
public Extension: E,
supportedVariants: string[],
waterLevel: number
) {
this.#supportedVariants = supportedVariants;
this.#waterLevel = waterLevel;

this.BrewCoffee = this.BrewCoffee.bind(this);
Expand All @@ -41,7 +63,7 @@ class CoffeeMachine {
await remote.SetCoffeeMachineBrewing(undefined, true);
});

if (!this.supportedVariants.includes(variant)) {
if (!this.#supportedVariants.includes(variant)) {
throw new Error("unsupported variant");
}

Expand Down Expand Up @@ -93,7 +115,11 @@ class RemoteControl {
async SetCoffeeMachineBrewing(ctx: IRemoteContext, brewing: boolean) {}
}

const service = new CoffeeMachine(["latte", "americano"], 1000);
const service = new CoffeeMachine(
new TeaBrewer(["darjeeling", "chai", "earlgrey"]),
["latte", "americano"],
1000
);

let clients = 0;

Expand Down

0 comments on commit 5fb705b

Please sign in to comment.