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 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}
Original file line number Diff line number Diff line change 11import { Dealer } from "zeromq"
22
3- import { Queue } from "./queue.js "
3+ import { Queue } from "./queue"
44
55async 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
2734main ( ) . catch ( err => {
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments