Permalink
Browse files

Add experimental support to merge promise queues, but I think this is…

…n't flexible enough to be generic. Expect it to be replaced by... better.
  • Loading branch information...
1 parent 97fe645 commit 9ee64987571c3734d03c6de6215dd52ccdc49af2 @rcaputo committed Mar 20, 2011
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/Reflex/Callback/Promise.pm
View
16 lib/Reflex/Callback/Promise.pm
@@ -33,6 +33,22 @@ sub next {
return shift @$queue;
}
+sub merge_into {
+ my ($self, $other_promise) = @_;
+
+ # Retain old queue for the moment.
+ my $old_queue = $self->queue();
+
+ # Redirect this promise into the other promise's queue.
+ $self->queue( $other_promise->queue() );
+
+ # If this promise contains events, move then into the other queue.
+ # TODO - Order is not maintained.
+ push @{$other_promise->queue()}, @$old_queue;
+
+ undef;
+}
+
1;
__END__

0 comments on commit 9ee6498

Please sign in to comment.