Skip to content

Commit

Permalink
README.md: fix javascript (#535)
Browse files Browse the repository at this point in the history
* Remove stray usage of Typescript typing in function arguments
* Remove shadowed `sub` variable, for clarity
* Import missing `Empty` payload object
  • Loading branch information
jordigh authored Nov 28, 2022
1 parent 2c0a6b8 commit 0c37d28
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ simply to illustrate not only how to create responses, but how the subject
itself is used to dispatch different behaviors.

```javascript
import { connect, StringCodec, Subscription } from "nats";
import { connect, StringCodec } from "nats";

// create a connection
const nc = await connect({ servers: "demo.nats.io" });
Expand All @@ -210,8 +210,8 @@ const nc = await connect({ servers: "demo.nats.io" });
const sc = StringCodec();

// this subscription listens for `time` requests and returns the current time
const sub = nc.subscribe("time");
(async (sub: Subscription) => {
const subscription = nc.subscribe("time");
(async (sub) => {
console.log(`listening for ${sub.getSubject()} requests...`);
for await (const m of sub) {
if (m.respond(sc.encode(new Date().toISOString()))) {
Expand All @@ -221,7 +221,7 @@ const sub = nc.subscribe("time");
}
}
console.log(`subscription ${sub.getSubject()} drained.`);
})(sub);
})(subscription);

// this subscription listens for admin.uptime and admin.stop
// requests to admin.uptime returns how long the service has been running
Expand Down Expand Up @@ -276,7 +276,7 @@ Here's a simple example of a client making a simple request from the service
above:

```javascript
import { connect, StringCodec } from "nats";
import { connect, Empty, StringCodec } from "nats";

// create a connection
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand Down

0 comments on commit 0c37d28

Please sign in to comment.