Skip to content

Commit ce7d050

Browse files
committed
fix: allow running pub-sub, push-pull, req-rep examples
1 parent 1c43975 commit ce7d050

File tree

9 files changed

+48
-10
lines changed

9 files changed

+48
-10
lines changed

examples/pub-sub/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (process.env.CI) {
2+
// exit after 1 second in CI environment
3+
setTimeout(() => {
4+
process.exit(0)
5+
}, 1000)
6+
}
7+
8+
/* eslint-disable import/no-unassigned-import */
9+
import "./publisher"
10+
import "./subscriber"

examples/pub-sub/publisher.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ async function run() {
66
await sock.bind("tcp://127.0.0.1:3000")
77
console.log("Publisher bound to port 3000")
88

9+
// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
910
while (true) {
1011
console.log("sending a multipart message envelope")
1112
await sock.send(["kitty cats", "meow!"])
@@ -15,4 +16,4 @@ async function run() {
1516
}
1617
}
1718

18-
run()
19+
run().catch(console.error)

examples/pub-sub/subscriber.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ async function run() {
1717
}
1818
}
1919

20-
run()
20+
run().catch(console.error)

examples/push-pull/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (process.env.CI) {
2+
// exit after 1 second in CI environment
3+
setTimeout(() => {
4+
process.exit(0)
5+
}, 1000)
6+
}
7+
8+
/* eslint-disable import/no-unassigned-import */
9+
import "./producer"
10+
import "./worker"

examples/push-pull/producer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ async function run() {
66
await sock.bind("tcp://127.0.0.1:3000")
77
console.log("Producer bound to port 3000")
88

9+
// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
910
while (true) {
1011
await sock.send("some work")
1112
await new Promise(resolve => {
@@ -14,4 +15,4 @@ async function run() {
1415
}
1516
}
1617

17-
run()
18+
run().catch(console.error)

examples/push-pull/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ async function run() {
1111
}
1212
}
1313

14-
run()
14+
run().catch(console.error)

examples/req-rep/client.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ async function run() {
66
sock.connect("tcp://127.0.0.1:3000")
77
console.log("Producer bound to port 3000")
88

9-
await sock.send("4")
10-
const [result] = await sock.receive()
9+
await sock.send(4)
10+
console.log("Request a calculation for 4")
1111

12-
console.log(result)
12+
const [result] = await sock.receive()
13+
console.log(`Received result: ${result}`)
1314
}
1415

15-
run()
16+
run().catch(console.error)

examples/req-rep/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (process.env.CI) {
2+
// exit after 1 second in CI environment
3+
setTimeout(() => {
4+
process.exit(0)
5+
}, 1000)
6+
}
7+
8+
/* eslint-disable import/no-unassigned-import */
9+
import "./client"
10+
import "./server"

examples/req-rep/server.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ async function run() {
66
await sock.bind("tcp://127.0.0.1:3000")
77

88
for await (const [msg] of sock) {
9-
await sock.send((2 * parseInt(msg.toString(), 10)).toString())
9+
// parse the message as a number
10+
const value = parseInt(msg.toString(), 10)
11+
12+
// calculate the result and send it back to the client
13+
const result = 2 * value
14+
await sock.send(result)
1015
}
1116
}
1217

13-
run()
18+
run().catch(console.error)

0 commit comments

Comments
 (0)