in reply to Mixing asynchronous data feed with synchronous program flow control
I like to encapsulate the mess and use a class.
The class first init() the websocket, then add() handlers and callbacks on receiving data from server. Finally, a send($message) sub to send whatever. Having a send() also deals with what haukex says about $TX being in the correct state.
Depending on what you want to do, you can make this class store a lot of data internally for the callbacks to use it. i.e. avoid having a lot of $TX and @command hanging around outside your class. One way would be to create one class for each situation you want your client to be used. Another is to write the basic class and functionality and then extend it with per-situation classes.
bw, bliako
|
|---|