Skip to content

Commit 6690995

Browse files
Adapt example
Signed-off-by: Xavier Geerinck <[email protected]>
1 parent 39bb8c1 commit 6690995

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

examples/http/actor/src/index.ts

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ const serverHost = "127.0.0.1"; // App Host of this Example Server
1010
const serverPort = "50001"; // App Port of this Example Server
1111
const daprAppId = "example-hello-world";
1212

13-
async function sleep(ms: number): Promise<void> {
14-
return new Promise(resolve => setTimeout(resolve, ms));
15-
}
16-
1713
async function start() {
1814
const server = new DaprServer(serverHost, serverPort, daprHost, daprPort);
1915
const client = new DaprClient(daprHost, daprPort);
@@ -39,43 +35,13 @@ async function start() {
3935
console.log("===============================================================");
4036
const actorId = "MyActorId1";
4137

42-
4338
const resRegisteredActors = await server.actor.getRegisteredActors();
4439
console.log(`Registered Actor Types: ${JSON.stringify(resRegisteredActors)}`);
4540

4641
console.log("[Dapr-JS][Example][Actors] Trying to invoke method 'say' with msg 'hello world'");
47-
const resActorInvokeSay = await client.actor.invoke("PUT", DemoActorSayImpl.name, actorId, "sayString", "Hello World");
42+
const actor = client.actor.create<DemoActorSayImpl>(DemoActorSayImpl);
43+
const resActorInvokeSay = await actor.sayString("Hello World");
4844
console.log(`[Dapr-JS][Example][Actors] Invoked Method and got data: ${resActorInvokeSay}`);
49-
50-
let resActorStateGet = await client.actor.stateGet(DemoActorSayImpl.name, actorId, "PropertyA");
51-
await client.actor.stateTransaction(DemoActorSayImpl.name, actorId, [
52-
{
53-
operation: "upsert",
54-
request: {
55-
key: "key-1",
56-
value: "my-new-data-1"
57-
}
58-
},
59-
{
60-
operation: "upsert",
61-
request: {
62-
key: "key-to-delete",
63-
value: "my-new-data-1"
64-
}
65-
},
66-
{
67-
operation: "delete",
68-
request: {
69-
key: "key-to-delete"
70-
}
71-
}
72-
]);
73-
74-
resActorStateGet = await client.actor.stateGet(DemoActorSayImpl.name, actorId, "key-to-delete");
75-
console.log(`[Dapr-JS][Example][Actors] Get State (should be empty): ${JSON.stringify(resActorStateGet)}`);
76-
77-
const resActorStateGet2 = await client.actor.stateGet(DemoActorSayImpl.name, actorId, "key-1");
78-
console.log(`[Dapr-JS][Example][Actors] Get State (should be my-new-data-1): ${JSON.stringify(resActorStateGet2)}`);
7945
}
8046

8147
start().catch((e) => {

0 commit comments

Comments
 (0)