You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm trying to publish an event to a server. Here's the code (this code works):
import*aszmqfrom"zeromq";import{Config}from"./config";constsleep=(ms: number)=>newPromise((resolve)=>setTimeout(resolve,ms));exportconstrunPub=async(config: Config)=>{constpublisher=newzmq.Publisher();publisher.connect(`tcp://127.0.0.1:${config.port}`);awaitsleep(100);// If I remove this, my code doesn't work... Any way to do this better?awaitpublisher.send(["mychannel",`J${JSON.stringify({channel: "mychannel",formats: {"http-stream": {content: "a chunk of data\n"}},})}`,]);};
If I remove the await sleep(100) my code does not work (I do not receive the data on the subscriber side). I'd like a cleaner way of doing things.
I also tried listening on connect event but it doesnt work (I do not receive data on the subscriber side) and the program takes forever to exit.
import*aszmqfrom"zeromq";import{Config}from"./config";constsleep=(ms: number)=>newPromise((resolve)=>setTimeout(resolve,ms));exportconstrunPub=async(config: Config)=>{constpublisher=newzmq.Publisher();// does not workawaitnewPromise<void>((resolve)=>{publisher.events.on("connect",()=>{console.log("connected");resolve();});publisher.connect(`tcp://127.0.0.1:${config.port}`);});awaitpublisher.send(["mychannel",`J${JSON.stringify({channel: "mychannel",formats: {"http-stream": {content: "a chunk of data\n"}},})}`,]);};
Describe the solution you'd like
Connect should return a promise if it involves async operations.
Describe alternatives you've considered
If you can listen for some sort of connection_success and connection_error events, then its allright.
Is your feature request related to a problem? Please describe.
I'm trying to publish an event to a server. Here's the code (this code works):
If I remove the
await sleep(100)
my code does not work (I do not receive the data on the subscriber side). I'd like a cleaner way of doing things.I also tried listening on
connect
event but it doesnt work (I do not receive data on the subscriber side) and the program takes forever to exit.Describe the solution you'd like
Connect should return a promise if it involves async operations.
Describe alternatives you've considered
If you can listen for some sort of
connection_success
andconnection_error
events, then its allright.Additional context
[email protected]
The text was updated successfully, but these errors were encountered: