Skip to content
Browse files

Add ability to wait for the next() occurrence of a particular event.

Using it in my rx-firmata work: $uno->put_handle("\xF0\x6B\xF7"); $uno->next('initialized');
  • Loading branch information...
1 parent f279d08 commit c5a86a1985c373e3ef0f96d71692a83acaa5d1e9 @rcaputo committed Mar 19, 2011
Showing with 20 additions and 3 deletions.
  1. +4 −1 docs/TODO.otl
  2. +16 −2 lib/Reflex/Role/Reactive.pm
View
5 docs/TODO.otl
@@ -126,7 +126,10 @@
[X] 100% Procedural design should be supported.
Some people will prefer procedural design.
[X] Objects are their own condvars.
- $object->wait() waits for the object to finish/destruct.
+ $object->next() waits for the object to emit a new event.
+ [X] 100% Wait for a particular event or one of several events.
+ A lot of time we're just waiting for an object to enter a particular state.
+ Event order is maintained; intermediate events are discarded.
[_] 0% Determine whether "role" is a confusing name.
Alternatives:
part
View
18 lib/Reflex/Role/Reactive.pm
@@ -609,11 +609,25 @@ sub run_all {
$singleton_session_id = undef;
}
+# TODO - Added semantics to wait for a specific event.
+# Need to document that.
+
sub next {
my $self = shift;
-
$self->promise() || $self->promise(Reflex::Callback::Promise->new());
- return $self->promise()->next();
+
+ return $self->promise()->next() unless @_;
+
+ # TODO - It's user friendly to accept a list and build a hash
+ # internally, but that adds runtime CPU overhead. On the other
+ # hand, passing in a hashref with dummy values kind of sucks for the
+ # user. I'd like to discuss the relative merits and costs of each
+ # option with someone.
+
+ my %which = map { $_ => 1 } @_;
+ while (my $next = $self->promise()->next()) {
+ return $next if exists $which{$next->{name}};
+ }
}
1;

0 comments on commit c5a86a1

Please sign in to comment.
Something went wrong with that request. Please try again.