Skip to content

Commit 7b553eb

Browse files
committed
docs: update the compat example
1 parent ce7d050 commit 7b553eb

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

examples/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ts-node": ">= 0"
99
},
1010
"scripts": {
11+
"build": "cd .. && pnpm build && cd ./examples && pnpm install",
1112
"majordomo": "ts-node ./majordomo/index.ts",
1213
"queue": "ts-node ./queue/index.ts",
1314
"threaded-worker": "ts-node ./threaded-worker/index.ts",

examples/v5-compat/index.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1+
/* eslint-disable */
12
const zmq = require("zeromq/v5-compat")
23

3-
const pub = zmq.socket("pub")
4-
const sub = zmq.socket("sub")
4+
function main() {
5+
const pub = zmq.socket("pub")
6+
const sub = zmq.socket("sub")
57

6-
pub.bind("tcp://*:3456", err => {
7-
if (err) {
8-
throw err
9-
}
8+
pub.on("bind", address => {
9+
console.log(`Bound to ${address}`)
10+
})
11+
12+
pub.bind("tcp://127.0.0.1:3456", err => {
13+
if (err) {
14+
throw err
15+
}
1016

11-
sub.connect("tcp://127.0.0.1:3456")
17+
sub.connect("tcp://127.0.0.1:3456")
18+
console.log("Subscriber connected to tcp://127.0.0.1:3456")
1219

13-
pub.send("message")
20+
sub.on("message", msg => {
21+
// Handle received message...
22+
console.log(`Received message: ${msg.toString()}`)
23+
})
1424

15-
sub.on("message", msg => {
16-
// Handle received message...
25+
pub.send("message")
1726
})
18-
})
27+
28+
if (process.env.CI) {
29+
// exit after 1 second in CI environment
30+
setTimeout(() => {
31+
process.exit(0)
32+
}, 2000)
33+
}
34+
}
35+
36+
main()

0 commit comments

Comments
 (0)