I am working on a Catalyst / psgi application that is very useful for asynchronous streaming, however outside of a simple timer (like here: http://www.catalystframework.org/calendar/2013/13 ), I am a little puzzled by how to implement more "global" events.
By global events, I mean things like:
- a periodic timer that is the same for all customers
- visit of one page by one client (but updates all clients)
- file statistics observer that will update all clients when a file changes.
Correct me if I am wrong, but for me all this is very similar to the example above, which will give each client a different counter. I would like to have events that take place "in all directions."
An example of what I tried (using # 2 from my list above):
has 'write_fh' => ( is => 'rw', predicate => 'has_write_fh' ); sub events : Path('/stream') Args(0) { my ( $self, $c ) = @_; $c->res->body(""); $c->res->content_type('text/event-stream'); $self->write_fh( $c->res->write_fh() ); } sub trigger : Path('/trigger') : Args(0) { my ( $self, $c ) = @_; $self->write_fh->write( *the event string* ); }
When I run this, it actually becomes larger than I would expect - the event fires, but it is no coincidence. When you open two browsers, sometimes the event is sent to one, and sometimes to the other.
Now, I think, I understand why this will never work - the client that hits / starts does not know about all the other clients that watch / stream, and therefore write_fh that I am trying to use will not come in handy.
But if each client request is in its own closed bubble, how can I access their stream from any other request?
Or am I completely mistaken ...?
source share