Skip to content

Commit

Permalink
docs: update the compat example
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 6, 2025
1 parent ce7d050 commit 7b553eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ts-node": ">= 0"
},
"scripts": {
"build": "cd .. && pnpm build && cd ./examples && pnpm install",
"majordomo": "ts-node ./majordomo/index.ts",
"queue": "ts-node ./queue/index.ts",
"threaded-worker": "ts-node ./threaded-worker/index.ts",
Expand Down
40 changes: 29 additions & 11 deletions examples/v5-compat/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
/* eslint-disable */
const zmq = require("zeromq/v5-compat")

const pub = zmq.socket("pub")
const sub = zmq.socket("sub")
function main() {
const pub = zmq.socket("pub")
const sub = zmq.socket("sub")

pub.bind("tcp://*:3456", err => {
if (err) {
throw err
}
pub.on("bind", address => {
console.log(`Bound to ${address}`)
})

pub.bind("tcp://127.0.0.1:3456", err => {
if (err) {
throw err
}

sub.connect("tcp://127.0.0.1:3456")
sub.connect("tcp://127.0.0.1:3456")
console.log("Subscriber connected to tcp://127.0.0.1:3456")

pub.send("message")
sub.on("message", msg => {
// Handle received message...
console.log(`Received message: ${msg.toString()}`)
})

sub.on("message", msg => {
// Handle received message...
pub.send("message")
})
})

if (process.env.CI) {
// exit after 1 second in CI environment
setTimeout(() => {
process.exit(0)
}, 2000)
}
}

main()

0 comments on commit 7b553eb

Please sign in to comment.