Permalink
Browse files

Update experimental promise collection to use Sender.

Make promise collections (Reflex::Collections that propagate events
from their contents) work with Nick Perez's Reflex::Sender.
  • Loading branch information...
1 parent 4a78509 commit 96596b2d80d6e143a16407cc8aa6e8b1db341cb9 @rcaputo committed Jan 6, 2011
Showing with 12 additions and 7 deletions.
  1. +4 −5 eg/eg-60-collection-promise.pl
  2. +1 −1 lib/Reflex/Collection.pm
  3. +7 −1 lib/Reflex/Sender.pm
@@ -120,11 +120,11 @@
sub on_result {
my ($self, $args) = @_;
- my $foo = $args->{_sender};
+ my $foo = $args->{_sender}->get_first_emitter();
my $value = $args->{value};
my $foo_type = ref $foo;
printf(
- "test collection got a result of %s! id => %s, value => %s\n",
+ "test collection got a result from %s! id => %s, value => %s\n",
$foo_type, $foo->id, $value
);
}
@@ -155,7 +155,6 @@
sub on_result {
my ($self, $args) = @_;
- $args->{member} = $args->{_sender};
$self->emit( event => "result", args => $args );
}
}
@@ -167,10 +166,10 @@
my $tcp = PromiseCollection->new();
while (my $e = $tcp->next) {
- my $member = $e->{arg}{member};
+ my $sender = $e->{arg}{_sender}->get_first_emitter();
printf(
"promise collection got a result of %s! id => %s, value => %s\n",
- ref($member), $member->id, $e->{arg}{value}
+ ref($sender), $sender->id, $e->{arg}{value}
);
}
View
@@ -64,7 +64,7 @@ sub forget {
sub cb_forget {
my ($self, $args) = @_;
- $self->_delete_object($args->{_sender}->[0]);
+ $self->_delete_object($args->{_sender}->get_last_emitter());
}
sub has_many {
View
@@ -20,7 +20,13 @@ has senders => (
sub push_emitter {
my ($self, $item) = @_;
push(@{$self->senders}, $item);
- weaken($self->senders->[-1]);
+
+ # TODO - If we weaken the senders, they can go undef if their
+ # objects are otherwise destroyed. This is kind of upsetting to the
+ # message recipient, so I've strengthened them (temporarily?) to
+ # explore the semantics. -- Rocco
+ #
+ #weaken($self->senders->[-1]);
}
no Moose;

0 comments on commit 96596b2

Please sign in to comment.