Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {Session} from "xconn";


async function examplePublish(session: Session) {
await session.publish("io.xconn.example", {args: ["test"], kwargs: {"key": "value"}});
await session.publish("io.xconn.example", ["test"], {"key": "value"});
}
```

Expand All @@ -78,7 +78,7 @@ import {Session} from "xconn";


async function exampleCall(session: Session) {
await session.call("io.xconn.echo", {args: [1, 2], kwargs: {"key": "value"}});
await session.call("io.xconn.echo", [1, 2], {"key": "value"});
}
```

Expand Down
14 changes: 5 additions & 9 deletions examples/pubsub/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ async function main() {
await session.publish(testTopic);

// publish event with args
await session.publish(testTopic, {args: ["Hello", "World"]});
await session.publish(testTopic, ["Hello", "World"]);

// publish event with kwargs
await session.publish(testTopic, {kwargs: {"key": "value"}});
await session.publish(testTopic, [], {"key": "value"});

// publish event with options
await session.publish(testTopic, {options: {"acknowledge": true}});
await session.publish(testTopic,[], {}, {"acknowledge": true});

// publish event with args & kwargs
await session.publish(testTopic, {args: ["Hello", "World"], kwargs: {"key": "value"}});
await session.publish(testTopic, ["Hello", "World"], {"key": "value"});

// publish event with args, kwargs & options
await session.publish(testTopic, {
args: ["Hello", "World"],
kwargs: {"key": "value"},
options: {"acknowledge": true}
});
await session.publish(testTopic, ["Hello", "World"], {"key": "value"}, {"acknowledge": true});

console.log(`Published events to ${testTopic}`);

Expand Down
18 changes: 6 additions & 12 deletions examples/rpc/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ async function main() {
const session = await connectAnonymous("ws://localhost:8080/ws", "realm1");

// Call procedure "io.xconn.echo" with args and kwargs
const result: Result = await session.call(testProcedureEcho, {
args: ["hello", "world"],
kwargs: {key: "value"},
});
const result: Result = await session.call(testProcedureEcho, ["hello", "world"], {key: "value"});
console.log(`Result of procedure '${testProcedureEcho}': args=${result.args}, kwargs=${result.kwargs}`);

// Call with only args
await session.call(testProcedureEcho, {args: ["hello", "world"]});
await session.call(testProcedureEcho, ["hello", "world"]);

// Call with only kwargs
await session.call(testProcedureEcho, {kwargs: {name: "john"}});
await session.call(testProcedureEcho, [], {name: "john"});

// Call with both args and kwargs
await session.call(testProcedureEcho, {args: [1, 2], kwargs: {name: "john"}});
await session.call(testProcedureEcho, [1, 2], {name: "john"});

// Call procedure "io.xconn.async.echo" with args and kwargs
const resultAsync: Result = await session.call(testProcedureAsyncEcho, {
args: ["hello", "xconn"],
kwargs: {key: "value"},
});
const resultAsync: Result = await session.call(testProcedureAsyncEcho, ["hello", "xconn"], {key: "value"});
console.log(`Result of procedure '${testProcedureAsyncEcho}': args=${resultAsync.args}, kwargs=${resultAsync.kwargs}`);

// Call sum procedure and print result
const sumResult: Result = await session.call(testProcedureSum, {args: [2, 2, 6]});
const sumResult: Result = await session.call(testProcedureSum, [2, 2, 6]);
console.log(`Sum=${sumResult.args?.[0]}`);

await session.close();
Expand Down