Skip to content

Commit

Permalink
feat: add @rivet-gg/actors (#1476)
Browse files Browse the repository at this point in the history
Fixes RVT-4188
  • Loading branch information
NathanFlurry committed Dec 2, 2024
1 parent 9765a83 commit f268644
Show file tree
Hide file tree
Showing 83 changed files with 3,490 additions and 26 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions examples/actor-simple/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ActorClient } from "../../sdks/actors/client/src/mod.ts"

async function main() {
const actorClient = new ActorClient("http://127.0.0.1:20025");

// Broadcast event
let broadcastActor;
{
const mod = 3;
broadcastActor = await actorClient.withTags({ name: "counter" });
broadcastActor.on("directCount", (count: unknown) => {
console.log(`Direct (n % ${mod}):`, count);
});
}

// Direct event
let directActor;
{
const mod = 3;
directActor = await actorClient.withTags({ name: "counter" });
directActor.on("directCount", (count: unknown) => {
console.log(`Broadcast:`, count);
});
}

// Simple RPC
{
const actor = await actorClient.withTags({ name: "counter" })
const newCount: number = await actor.rpc("increment", 5);
console.log('Simple RPC:', newCount);
actor.disconnect();
}

// Multiple RPC calls
{
const actor = await actorClient.withTags({ name: "counter" });

for (let i = 0; i < 10; i++) {
const output = await actor.rpc("increment", 5);
console.log('Reusing handle:', output);
}

actor.disconnect();
}

// WebSocket
{
const actor = await actorClient.withTags({ name: "counter" });
for (let i = 0; i < 10; i++) {
const newOutput = await actor.rpc("increment", 5);
console.log('WebSocket:', newOutput);
}

actor.disconnect();
}

await directActor.rpc("destroyMe");

// Disconnect all actors before
broadcastActor.disconnect();
directActor.disconnect();
}

await main();
Loading

0 comments on commit f268644

Please sign in to comment.