use Mojo::IOLoop; my $clients = {}; my $lasttime = time; Mojo::IOLoop->recurring( 1 => sub { if ( my( $newMessages, $time ) = GetNewFromDb($lasttime) ) { $lasttime = $time; for my $msg (@$newMessages) { MsgToClients( $msg, $clients ); } } }, ); websocket '/echo' => sub { ... $self->receive_message( sub { my ($self, $msg) = @_; MsgToDb( $self, $msg ); ## NO ## MsgToClients( $self, $msg , $clients ); ## NO }, ); ... }; sub GetNewFromDb { my( $lasttime ) = @_; ... my $time = eval { $last_message->{time} }; return $messages, $time; } #### 20:15 ghandi Hi There! I've been playing around with the Mojo WebSocket Chat-Example from https://github.com/kraih/mojo/wiki/Writi​ng-websocket-chat-using-Mojolicious-Lite 20:15 And now i'm wondering: Do i realy need to keep track of the clients myself in %clients? Wouldn't it be cooler to just use a custom event that i emit on a new incoming message? 20:16 gtodd hmm 20:17 define "cooler" :-) 20:17 Anyway maybe you could answer questions about Mojo on Stackoverflow and become famous :) 20:17 there's one up there about websockets ... 20:17 for me cooler would be "faster" 20:18 ghandi cooler like more slick 'n sexy. Like let the Event-System take care of the Client-Management since it already knows about the connections 20:18 gtodd POE could be sexy but Mojo-POE I don't know 20:20 sri ghandi: no, in fact, that example is not very good to begin with 20:20 doesn't scale past one process 20:20 gtodd ghandi: what you just described seems too easy or obvious 20:21 oops hehe I agree with sri 20:21 sri it's a minimal example, anything serious needs a backend like redis pub/sub 20:21 gtodd ghandi: btw. I meant too obvious or easy because it makes sense to me and I am usually wrong :-) 20:22 ghandi so in my case: I'm thinking about some live-intaraction page, where multiple people whatch the page while a single person sends in some updates. For this i need a dedicated "collaboration"-Server to which mojo talks? 20:26 btyler like sri said, redis with pub/sub is precisely that 'middle person' that multiple mojo processes can talk to 20:27 ghandi But don't i loose then the event-driven part of the Websockets? The client then has to poll the app which then will lookup on redis? 20:28 sri i think Mojo::Redis is actually battle tested now with wirc using pub/sub too 20:30 batman: Mojo::JSON uses render_json in the example 20:30 Drossel joined #mojo 20:31 bek ghandi: /quit 20:33 ghandi sri: Mojo::Redis looks interesting. So just to get something right: The Mojo-Event-System is Process-Based, right? Which means: Client A on $PID 1 can't talk to Client B on $PID 2? 20:34 sri that's how everything in perl works 20:35 ghandi Ok, thanks ;)