AnyEvent-Capture
view release on metacpan or search on metacpan
---
abstract: 'Call asynchronous APIs synchronously'
author:
- 'Rebecca Turner <becca@referencethis.com>'
build_requires: {}
configure_requires:
ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.300020, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
"ABSTRACT" => "Call asynchronous APIs synchronously",
"AUTHOR" => "Rebecca Turner <becca\@referencethis.com>",
"BUILD_REQUIRES" => {},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.30"
},
"DISTNAME" => "AnyEvent-Capture",
"EXE_FILES" => [],
"LICENSE" => "perl",
"NAME" => "AnyEvent::Capture",
"PREREQ_PM" => {
This archive contains the distribution AnyEvent-Capture,
version 0.1.1:
Call asynchronous APIs synchronously
This software is copyright (c) 2012 by Rebecca Turner.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
lib/AnyEvent/Capture.pm view on Meta::CPAN
# ABSTRACT: Call asynchronous APIs synchronously
package AnyEvent::Capture;
{
$AnyEvent::Capture::VERSION = '0.1.1';
}
use strict;
use warnings;
use AnyEvent ();
use Sub::Exporter -setup => {
exports => [qw( capture )],
groups => { default => [qw( capture )] },
lib/AnyEvent/Capture.pm view on Meta::CPAN
1;
__END__
=pod
=encoding utf-8
=head1 NAME
AnyEvent::Capture - Call asynchronous APIs synchronously
=head1 VERSION
version 0.1.1
=head1 SYNOPSIS
use AnyEvent::Capture;
use AnyEvent::Socket qw( inet_aton );
# Call the async version of inet_aton in a synchronous fashion, but
# while we're doing this other events will fire.
my @ips = capture { inet_aton( 'localhost', shift ) };
# An example of waiting for a child without blocking events from firing
# while we wait.
sub wait_for_child($) {
my( $pid ) = @_;
my($rpid,$rstatus) = capture { AnyEvent->child(pid=>$pid, cb=>shift) };
return $rstatus;
}
lib/AnyEvent/Capture.pm view on Meta::CPAN
=head1 HELPERS
=head2 sub capture( CodeRef $todo ) returns Any
Executes $todo, passing it a CodeRef to be used as an event listener. After
$todo returns, it enters the event loop and waits till the CodeRef is
called. The return value of $todo will be stored until such time as the
CodeRef is called. It then returns the arguments that were passed to the
CodeRef.
In so doing, it allows you to call an asychronous function in a synchronous
fashion.
This module is similar to L<Data::Monad::CondVar> but much simpler. You
could write the example using L<Data::Monad::CondVar> this way:
my @ips = (as_cv {inet_aton( 'localhost', shift ) })->recv;
=head1 SEE ALSO
( run in 0.692 second using v1.01-cache-2.11-cpan-0d8aa00de5b )