Permalink
Browse files

Rename observe() to watch(). Rename wait() to next().

  • Loading branch information...
1 parent 15add25 commit 5f9458c064965a1e86d4ac43f93ef3bc50b95056 @rcaputo committed Jun 16, 2010
View
@@ -6,10 +6,10 @@ Reflex::Role::Object
Has the cb() member.
BUILD
Maps constructor parameters to callbacks.
- Maps callback types to observers:
- discrete callbacks = discrete observers
- role callbacks = role observers
- no callbacks = unobserved (promise?)
+ Maps callback types to watchers:
+ discrete callbacks = discrete watchers
+ role callbacks = role watchers
+ no callbacks = unwatched (promise?)
=head1 Reflex::Role::Object::BUILD calls cb_gather()
@@ -61,11 +61,11 @@ my $timer = Reflex::Timer->new(
# cb_promise
);
-while (my $event = $timer->wait()) {
+while (my $event = $timer->next()) {
...;
}
-=head1 Observer.
+=head1 Watcher.
=cut
@@ -75,8 +75,8 @@ my $timer = Reflex::Timer->new(
promise => 1,
);
-$self->observe(
- observed => $timer,
+$self->watch(
+ watcher => $timer,
event => "tick",
callback => ANY_RCB_EXCEPT_PROMISE,
);
@@ -85,9 +85,9 @@ $self->observe(
The current syntax is too verbose.
-$watcher has no purpose except to call observe().
+$watcher has no purpose except to call watch().
-Perhaps $watcher could be replaced by a Promise class that observes
+Perhaps $watcher could be replaced by a Promise class that watches
and then returns events? Similar to PromiseThing in
eg-25-rcb-promise.pl?
@@ -112,8 +112,8 @@ my $timer = Reflex::Timer->new(
auto_repeat => 1,
);
-$watcher->observe($timer, cb_promise(\$promise));
+$watcher->watch($timer, cb_promise(\$promise));
-while (my $event = $promise->wait()) {
- eg_say("wait() returned an event (@$event)");
+while (my $event = $promise->next()) {
+ eg_say("next() returned an event (@$event)");
}
View
@@ -18,12 +18,12 @@ has promise => (
sub BUILD {
my $self = shift;
- $self->observe($self->object(), cb_promise($self->promise()));
+ $self->watch($self->object(), cb_promise($self->promise()));
}
-sub wait {
+sub next {
my $self = shift;
- return ${$self->promise()}->wait();
+ return ${$self->promise()}->next();
}
1;
@@ -10,8 +10,8 @@
# "waitron". It emits "tick" events that are handled by the watcher's
# on_waitron_tick() method.
#
-# An object may observe another in more than one role. In this test
-# case, the Reflex::Timer is also observed in the "waitroff" role.
+# An object may watch another in more than one role. In this test
+# case, the Reflex::Timer is also watched in the "waitroff" role.
# The on_waitroff_tick() method is also invoked.
use warnings;
@@ -51,8 +51,8 @@
ok( (defined $self->timer()), "started timer object in waitron role" );
# It's possible to mix and match.
- pass("also observing timer as the waitroff role");
- $self->observe($self->timer() => cb_role($self, "waitroff"));
+ pass("also watching timer as the waitroff role");
+ $self->watch($self->timer() => cb_role($self, "waitroff"));
}
my $countdown = 3;
@@ -21,7 +21,7 @@
auto_repeat => 1,
);
- $self->observe($self->{ticker}, cb_role($self, "ticker"));
+ $self->watch($self->{ticker}, cb_role($self, "ticker"));
}
sub on_ticker_tick {
@@ -16,8 +16,8 @@
my $promise;
my $watcher = Reflex::Object->new();
-$watcher->observe($timer, cb_promise(\$promise));
+$watcher->watch($timer, cb_promise(\$promise));
-while (my $event = $promise->wait()) {
- eg_say("wait() returned an event ($event->{name})");
+while (my $event = $promise->next()) {
+ eg_say("next() returned an event ($event->{name})");
}
@@ -16,6 +16,6 @@
)
);
-while (my $event = $p->wait()) {
- eg_say("wait() returned an event ($event->{name})");
+while (my $event = $p->next()) {
+ eg_say("next() returned an event ($event->{name})");
}
View
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
# This is pretty close to the final syntax.
-# TODO - Provide a way to wait() on multiple objects at once.
+# TODO - Provide a way to next() on multiple objects at once.
# TODO - Clean out all previous promise-like examples.
use warnings;
@@ -17,6 +17,6 @@
auto_repeat => 1,
);
-while (my $event = $t->wait()) {
- eg_say("wait() returned an event ($event->{name})");
+while (my $event = $t->next()) {
+ eg_say("next() returned an event ($event->{name})");
}
@@ -1,7 +1,8 @@
#!/usr/bin/env perl
# This is pretty close to the final syntax.
-# TODO - Provide a way to wait() on multiple objects at once.
+# TODO - Provide a way to next() on multiple objects at once.
+# ...... maybe by next() on a collection?
# TODO - Clean out all previous promise-like examples.
use warnings;
@@ -120,14 +121,14 @@
my $rh = RoleHandler->new();
### Poll for events with a condvar-like promise construct. Goes last
-### because the while() loop will "block". Meanwhile, wait() is also
+### because the while() loop will "block". Meanwhile, next() is also
### allowing the other timers to run.
my $pt = Reflex::Timer->new(
interval => 1 + rand(),
auto_repeat => 1,
);
-while (my $event = $pt->wait()) {
+while (my $event = $pt->next()) {
eg_say("promise timer returned an event ($event->{name})");
}
@@ -18,7 +18,7 @@
my $connector = Reflex::Connector->new(remote_port => 12345);
# Wait for the connection to finish.
-my $event = $connector->wait();
+my $event = $connector->next();
# Failure? Ok, bye.
if ($event->{name} eq "failure") {
@@ -39,7 +39,7 @@
$stream->put("Hello, world!\n");
# Handle a response.
-$event = $stream->wait();
+$event = $stream->next();
if ($event->{name} eq "data") {
eg_say("Got echo response: $event->{arg}{data}");
}
View
@@ -16,6 +16,6 @@
);
my $usr2 = Reflex::Signal->new( name => "USR2" );
-while ($usr2->wait()) {
+while ($usr2->next()) {
eg_say("Got SIGUSR2.");
}
View
@@ -28,5 +28,5 @@
$s1->put("test request\n");
# Wait for it to arrive on Stream 2 (socket 2a).
-my $e = $s2->wait();
+my $e = $s2->next();
warn $e->{name}, ": ", $e->{arg}{data};
View
@@ -102,7 +102,7 @@ warnings, strict, and base instead. Reflex::Object provides emit().
The next object uses Echoer. It creates an Echoer and pings it to get
started. It also reacts to "pong" events by pinging the Echoer again.
-Reflex::Trait::Observer implicitly observes the object in echoer(),
+Reflex::Trait::Observer implicitly watches the object in echoer(),
mapping its "pong" event to the on_echoer_pong() method.
package Pinger;
@@ -181,8 +181,8 @@ Reflex::Timer used differently elsewhere.
auto_repeat => 1,
);
- while (my $event = $t->wait()) {
- eg_say("wait() returned an event (@$event)");
+ while (my $event = $t->next()) {
+ eg_say("next() returned an event (@$event)");
}
=head1 BUNDLED CLASSES AND DOCUMENTATION INDEX
@@ -213,7 +213,7 @@ Reflex bundles a number of helpful base classes to get things started.
Reflex::POE::Event - represents POE events in Reflex
Reflex::POE::Postback - represents POE postbacks in Reflex
Reflex::Trait::Emitter - emit events when a member's value changes
- Reflex::Trait::Observer - observe events emitted by a member object
+ Reflex::Trait::Observer - watch events emitted by a member object
Reflex - helper functions and documentation
=head1 ASSISTANCE
@@ -15,7 +15,7 @@ sub deliver {
push @{$self->queue()}, { name => $event, arg => $arg };
}
-sub wait {
+sub next {
my $self = shift;
my $queue = $self->queue();
@@ -46,7 +46,7 @@ Used within Reflex:
auto_repeat => 1,
);
- while (my $event = $pt->wait()) {
+ while (my $event = $pt->next()) {
eg_say("promise timer returned an event (@$event)");
}
@@ -57,7 +57,7 @@ Low-level usage:
my $cb = Reflex::Callback::Promise->new();
$cb->deliver( greet => { name => "world" } );
- my $event = $cb->wait();
+ my $event = $cb->next();
print "event '$event->{name}': hello, $event->{arg}{name}\n";
=head1 DESCRIPTION
@@ -71,16 +71,16 @@ will be used instead of raw Reflex::Callback::Promise objects.
Reflex::Callback::Promise's constructor takes no parameters. It
creates a promise queue that is populated by deliver() and drained by
-wait(). Furthermore, wait() will block as necessary until it can
+next(). Furthermore, next() will block as necessary until it can
return an event. This requires the help of some form of concurrency,
currently hardcoded to use POE.
A future version may delegate the POE dependency to a subclass.
-=head2 wait
+=head2 next
-Reflex::Callback::Promise's wait() method retrieves the next pending
-event held in the object's queue. If the queue is empty, wait() will
+Reflex::Callback::Promise's next() method retrieves the next pending
+event held in the object's queue. If the queue is empty, next() will
dispatch other events until some asynchronous code enqueues a new event
in the promise's queue.
View
@@ -15,7 +15,7 @@ has objects => (
sub remember {
my ($self, $object) = @_;
- $self->observe($object, stopped => cb_method($self, "cb_forget"));
+ $self->watch($object, stopped => cb_method($self, "cb_forget"));
$self->objects()->{$object} = $object;
}
View
@@ -130,7 +130,7 @@ Reflex objects may also be used in condvar-like ways. This excerpts
from eg/eg-38-promise-client.pl in the distribution.
my $connector = Reflex::Connector->new(remote_port => 12345);
- my $event = $connector->wait();
+ my $event = $connector->next();
if ($event->{name} eq "failure") {
eg_say("connection error $event->{arg}{errnum}: $event->{arg}{errstr}");
View
@@ -109,7 +109,7 @@ L<Reflex::POE::Wheel::Run> may serve as an example.
=head1 DESCRIPTION
Reflex::POE::Wheel is a base class for Reflex objects that wrap and
-observe POE::Wheel objects. Subclasses define a handful of methods
+watch POE::Wheel objects. Subclasses define a handful of methods
that describe the wheels they wrap. Reflex::POE::Wheel will use the
configuration to validate constructor parameters, map wheel events to
Reflex events, and map positional callback parameters to named ones.
Oops, something went wrong.

0 comments on commit 5f9458c

Please sign in to comment.