Skip to content

Commit ef16f21

Browse files
committed
fix: fix the queue example
1 parent f4526f6 commit ef16f21

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

examples/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"scripts": {
1111
"majordomo": "ts-node ./majordomo/index.ts",
1212
"queue": "ts-node ./queue/index.ts",
13-
"threaded-worker": "ts-node ./threaded-worker/index.ts"
13+
"threaded-worker": "ts-node ./threaded-worker/index.ts",
14+
"pub-sub": "ts-node ./pub-sub/index.ts",
15+
"push-pull": "ts-node ./push-pull/index.ts",
16+
"req-rep": "ts-node ./req-rep/index.ts",
17+
"v5-compat": "node ./v5-compat/index.js"
1418
}
1519
}

examples/queue/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import {Dealer} from "zeromq"
22

3-
import {Queue} from "./queue.js"
3+
import {Queue} from "./queue"
44

55
async function main() {
66
const sender = new Dealer()
77
await sender.bind("tcp://127.0.0.1:5555")
8+
console.log("sender bound to port 5555")
89

910
const queue = new Queue(sender)
10-
await queue.send("hello")
11-
await queue.send("world!")
12-
await queue.send(null)
11+
12+
const sent = Promise.all([
13+
queue.send("hello"),
14+
queue.send("world!"),
15+
queue.send(null),
16+
])
1317

1418
const receiver = new Dealer()
1519
receiver.connect("tcp://127.0.0.1:5555")
20+
console.log("receiver connected to port 5555")
1621

1722
for await (const [msg] of receiver) {
1823
if (msg.length === 0) {
@@ -22,6 +27,8 @@ async function main() {
2227
console.log(`received: ${msg}`)
2328
}
2429
}
30+
31+
await sent
2532
}
2633

2734
main().catch(err => {

examples/queue/queue.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class Queue {
1212
}
1313

1414
send(msg: MessageLike) {
15+
console.log(`Sending message: ${msg}`)
1516
if (this.queue.length > this.max) {
1617
throw new Error("Queue is full")
1718
}

0 commit comments

Comments
 (0)