Websocket Usage #1986
Unanswered
tophopstop
asked this question in
Q&A
Websocket Usage
#1986
Replies: 1 comment 1 reply
-
If I recall correctly, yes there effectively is a queue, the write buffer. You might want to see what happens if you use the drain callback to prevent proceeding until the data has been written. I would make a send_p function and await it, something like my $send_p = sub ($self, @args) {
my $p = Mojo::Promise->new;
$self->send(@args, sub { $p->resolve });
return $p;
};
...
$self->on(json => async sub {
await $self->$send_p({
json => {
type=>'info',
message => "Starting Testing."
}
});
});
I haven't tested any of this, its just my pseudocode on yours |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've got mojo app based dev opps system where a master console coordinates off dev ops related processes on agents on multiple servers.
I used websocket connection between the console and agents. The console kicks off an operation and then gets feedback about task from the agent comes back over the same connection.
I've noticed that the messages back from the agent don't arrive back to console in real time. They appear to get queued up until the websocket connection is finished, then they all appear arrive at once back in the console.
Here's some pseudo code for the controller code for the route that handles the websocket on the agent...
Shouldn't the websocket sends emit their messages as they're called? When I test my code, the 4 messages are all received at the same time despite being 'sent' at different times.
Please let me know if I'm missing something conceptually with websockets in general or in how to use them with Mojolicious. Thanks for the help!
Beta Was this translation helpful? Give feedback.
All reactions