summaryrefslogtreecommitdiff
path: root/Tanja.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-02-16 17:03:03 +0100
committerYorhel <git@yorhel.nl>2012-02-16 17:03:03 +0100
commitb689af6c792a4e9a243d6260a2718f49e98b9411 (patch)
treefe82551e57b860208b9f8b587072431e5e3a8668 /Tanja.pm
parent5be2f049b3f0e57c36184070dc348312c81d437e (diff)
Use AnyEvent::postpone() to make tuple dispatch asynchronous
Diffstat (limited to 'Tanja.pm')
-rw-r--r--Tanja.pm14
1 files changed, 7 insertions, 7 deletions
diff --git a/Tanja.pm b/Tanja.pm
index 6827cd8..1062cda 100644
--- a/Tanja.pm
+++ b/Tanja.pm
@@ -1,8 +1,3 @@
-# Note: this implementation isn't really asynchronous for communication between
-# local sessions. Not sure yet whether this is a problem. (Can be fixed easily
-# by using single-fire idle events to dispatch tuples. Comes at a performance
-# cost, though).
-
package Tanja;
use strict;
@@ -56,7 +51,11 @@ sub link {
sub send {
my($s, $t, $cb) = @_;
# TODO: fix return path
- $_->[2]->($t, undef) for(grep Tanja::match($_->[0], $t), values %{$s->{pat}});
+ for my $reg (grep Tanja::match($_->[0], $t), values %{$s->{pat}}) {
+ AnyEvent::postpone {
+ $reg->[2]->($t, undef);
+ }
+ }
}
@@ -102,7 +101,8 @@ sub new {
# Returns: (ignored)
sub reg {
my($s, $pat, $reply, $cb) = @_;
- my $id = $s->{server}->_register($pat, $reply, $cb);
+ my $id;
+ $id = $s->{server}->_register($pat, $reply, sub { $s->{pat}{$id} && $cb->(@_) });
$s->{pat}{$id} = 1;
return $id;
}