Skip to content

Commit

Permalink
more tests for one-time events
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 21, 2015
1 parent e6360a8 commit 978b14f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion t/mojo/eventemitter.t
Expand Up @@ -103,10 +103,20 @@ is $once, 1, 'event was not emitted again';
$e->emit('one_time');
is $once, 1, 'event was not emitted again';

# One-time event used directly
$e = Mojo::EventEmitter->new;
ok !$e->has_subscribers('foo'), 'no subscribers';
$once = 0;
my $cb = $e->once(foo => sub { $once++ });
ok $e->has_subscribers('foo'), 'has subscribers';
$cb->();
is $once, 1, 'event was emitted once';
ok !$e->has_subscribers('foo'), 'no subscribers';

# Unsubscribe
$e = Mojo::EventEmitter->new;
my $counter;
my $cb = $e->on(foo => sub { $counter++ });
$cb = $e->on(foo => sub { $counter++ });
$e->on(foo => sub { $counter++ });
$e->on(foo => sub { $counter++ });
$e->unsubscribe(foo => $e->once(foo => sub { $counter++ }));
Expand Down

0 comments on commit 978b14f

Please sign in to comment.