AnyEvent-Blackboard
view release on metacpan or search on metacpan
lib/AnyEvent/Blackboard.pm view on Meta::CPAN
=cut
=back
=head1 METHODS
=over 4
=item timeout SECONDS, [ KEY, [, DEFAULT ] ]
Set a timer for N seconds to provide "default" value as a value, defaults to
`undef`. This can be used to ensure that blackboard workflows do not reach a
dead-end if a required value is difficult to obtain.
=cut
sub timeout {
my ($self, $seconds, $key, $default) = @_;
$key = [ $key ] unless (ref $key eq "ARRAY");
unless ($self->has($key)) {
my $guard = AnyEvent->timer(
after => $seconds,
cb => sub {
unless ($self->has($key)) {
$self->put($_ => $default) for @$key;
}
}
);
# Cancel the timer if we find the object first (otherwise this is a NOOP).
$self->_watch($key, sub { undef $guard });
}
}
=item watch KEYS, WATCHER [, KEYS, WATCHER ]
=item watch KEY, WATCHER [, KEYS, WATCHER ]
Overrides L<Async::Blackboard> only for the purpose of adding a timeout.
( run in 1.130 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )