0
@@ -98,7 +98,7 @@ If your app is called C<App>, then:
0
=head3 Event Architecture
0
-TODO - explain
using IRC as a metaphor
0
+TODO - explain
, possibly using IRC as a metaphor
0
Events (and my current preference for ambient event generation)
0
@@ -111,44 +111,79 @@ Subscribers
0
=head3 RESTless Controllers
0
-I'm figuring this out as I go along...
0
+The following is the C<Event> controller from the Bavl project. It is included
0
+here to give you something to ponder while I think about how to explain this
0
+better. (I'm figuring this out as I go along.)
0
Event => [ '/@event' ],
0
warn "coro [$Coro::current]";
0
+ my $input = $self->input;
0
+ my @ch = channels($input->{channels});
0
+ map { my $ch = $bavl->channels->{$_}; $ch->read } @ch;
0
- $cr->print(encode_json(
[{ type => 'Chat', message => 'Hi' }]));
0
+ $cr->print(encode_json(
\@events));
0
# Hold for a brief moment until the next long poll request comes in.
0
warn "waiting for next request";
0
- # TODO Try starting up 1 coroutine per channel.
0
- # TODO Each coroutine will have the same Coro::Signal object.
0
- # TODO The first one who sends a signal wins.
0
- # TODO The losers will have to be terminated somehow.
0
- warn "waiting for signal";
0
- $signal->timed_wait(20);
0
+ my $channels = [ $cr->param('channels') ];
0
+ @ch = channels($channels);
0
+ # Try starting up 1 coroutine per channel.
0
+ # Each coroutine will have the same Coro::Signal object => $activity.
0
+ my $activity = Coro::Signal->new;
0
+ my $ch = $bavl->channels->{$_};
0
+ async { $ch->signal->wait; $activity->broadcast };
0
+ # The first one who sends a signal to $activity wins.
0
+ warn "waiting for activity on any of (@ch)";
0
+ $activity->timed_wait(20);
0
+ # Cancel the remaining coros.
0
+ for (@coros) { $_->cancel }
0
+ # The current POST action exists for debugging purposes, only.
0
+ # In practice, channel updates will happen ambiently
0
+ # when model data changes.
0
+ # Hooks will be put into place to facilitate this.
0
+ # In the future, the POST action may be used as a notification
0
+ # to the server side that $.ev.stop() happened
0
+ my $input = $self->input;
0
+ my $ch = $bavl->channels->{ $input->{channels} };
0
+ $ch->write({ type => 'time', value => scalar(localtime) });
0
queue => { get => 'event' },
0
+This might look scary, but if we're lucky, we'll be able to turn this into
0
=head3 Long Polling with jQuery on the Client Side
Comments
No one has commented yet.