Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

io::async::test(3pm) [debian man page]

IO::Async::Test(3pm)					User Contributed Perl Documentation				      IO::Async::Test(3pm)

NAME
"IO::Async::Test" - utility functions for use in test scripts SYNOPSIS
use Test::More tests => 1; use IO::Async::Test; use IO::Async::Loop; my $loop = IO::Async::Loop->new; testing_loop( $loop ); my $result; $loop->do_something( some => args, on_done => sub { $result = the_outcome; } ); wait_for { defined $result }; is( $result, what_we_expected, 'The event happened' ); ... my $buffer = ""; my $handle = IO::Handle-> ... wait_for_stream { length $buffer >= 10 } $handle => $buffer; is( substr( $buffer, 0, 10, "" ), "0123456789", 'Buffer was correct' ); DESCRIPTION
This module provides utility functions that may be useful when writing test scripts for code which uses "IO::Async" (as well as being used in the "IO::Async" test scripts themselves). Test scripts are often synchronous by nature; they are a linear sequence of actions to perform, interspersed with assertions which check for given conditions. This goes against the very nature of "IO::Async" which, being an asynchronisation framework, does not provide a linear stepped way of working. In order to write a test, the "wait_for" function provides a way of synchronising the code, so that a given condition is known to hold, which would typically signify that some event has occured, the outcome of which can now be tested using the usual testing primitives. Because the primary purpose of "IO::Async" is to provide IO operations on filehandles, a great many tests will likely be based around connected pipes or socket handles. The "wait_for_stream" function provides a convenient way to wait for some content to be written through such a connected stream. FUNCTIONS
testing_loop( $loop ) Set the "IO::Async::Loop" object which the "wait_for" function will loop on. wait_for( $condfunc ) Repeatedly call the "loop_once" method on the underlying loop (given to the "testing_loop" function), until the given condition function callback returns true. To guard against stalled scripts, if the loop indicates a timeout for 10 consequentive seconds, then an error is thrown. wait_for_stream( $condfunc, $handle, $buffer ) As "wait_for", but will also watch the given IO handle for readability, and whenever it is readable will read bytes in from it into the given buffer. The buffer is NOT initialised when the function is entered, in case data remains from a previous call. $buffer can also be a CODE reference, in which case it will be invoked being passed data read from the handle, whenever it is readable. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::Test(3pm)

Check Out this Related Man Page

IO::Async::Timer(3pm)					User Contributed Perl Documentation				     IO::Async::Timer(3pm)

NAME
"IO::Async::Timer" - base class for Notifiers that use timed delays DESCRIPTION
This module provides a subclass of IO::Async::Notifier for implementing notifiers that use timed delays. For specific implementations, see one of the subclasses: o IO::Async::Timer::Absolute - event callback at a fixed future time o IO::Async::Timer::Countdown - event callback after a fixed delay o IO::Async::Timer::Periodic - event callback at regular intervals CONSTRUCTOR
$timer = IO::Async::Timer->new( %args ) Constructs a particular subclass of "IO::Async::Timer" object, and returns it. This constructor is provided for backward compatibility to older code which doesn't use the subclasses. New code should directly construct a subclass instead. mode => STRING The type of timer to create. Currently the only allowed mode is "countdown" but more types may be added in the future. Once constructed, the "Timer" will need to be added to the "Loop" before it will work. It will also need to be started by the "start" method. METHODS
$running = $timer->is_running Returns true if the Timer has been started, and has not yet expired, or been stopped. $timer->start Starts the Timer. Throws an error if it was already running. If the Timer is not yet in a Loop, the actual start will be deferred until it is added. Once added, it will be running, and will expire at the given duration after the time it was added. As a convenience, $timer is returned. This may be useful for starting timers at construction time: $loop->add( IO::Async::Timer->new( ... )->start ); $timer->stop Stops the Timer if it is running. If it has not yet been added to the "Loop" but there is a start pending, this will cancel it. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::Timer(3pm)
Man Page