File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 10
10
"scripts" : {
11
11
"majordomo" : " ts-node ./majordomo/index.ts" ,
12
12
"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"
14
18
}
15
19
}
Original file line number Diff line number Diff line change 1
1
import { Dealer } from "zeromq"
2
2
3
- import { Queue } from "./queue.js "
3
+ import { Queue } from "./queue"
4
4
5
5
async function main ( ) {
6
6
const sender = new Dealer ( )
7
7
await sender . bind ( "tcp://127.0.0.1:5555" )
8
+ console . log ( "sender bound to port 5555" )
8
9
9
10
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
+ ] )
13
17
14
18
const receiver = new Dealer ( )
15
19
receiver . connect ( "tcp://127.0.0.1:5555" )
20
+ console . log ( "receiver connected to port 5555" )
16
21
17
22
for await ( const [ msg ] of receiver ) {
18
23
if ( msg . length === 0 ) {
@@ -22,6 +27,8 @@ async function main() {
22
27
console . log ( `received: ${ msg } ` )
23
28
}
24
29
}
30
+
31
+ await sent
25
32
}
26
33
27
34
main ( ) . catch ( err => {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export class Queue {
12
12
}
13
13
14
14
send ( msg : MessageLike ) {
15
+ console . log ( `Sending message: ${ msg } ` )
15
16
if ( this . queue . length > this . max ) {
16
17
throw new Error ( "Queue is full" )
17
18
}
You can’t perform that action at this time.
0 commit comments