Acme-Parataxis
view release on metacpan or search on metacpan
lib/Acme/Parataxis/Driver/Mojo.pod view on Meta::CPAN
=pod
=encoding utf8
=head1 NAME
Acme::Parataxis::Driver::Mojo - Mojo::IOLoop and Mojo::Reactor Driver for Parataxis
=head1 SYNOPSIS
use v5.40;
use Acme::Parataxis qw[await_read await_sleep fiber];
use Mojo::IOLoop;
# Attach Mojo's loop:
Acme::Parataxis->attach_loop( Mojo::IOLoop->new );
Acme::Parataxis::run( sub {
my $ponger = fiber {
await_sleep(30);
syswrite( $socket, "ping\n" );
};
await_read( $socket, 2000 );
} );
Acme::Parataxis->detach_loop;
# Or drive a bare Mojo::Reactor directly:
Acme::Parataxis->attach_loop( $ioloop->reactor );
=head1 DESCRIPTION
C<Acme::Parataxis::Driver::Mojo> connects Parataxis to Mojolicious event loops. It allows fibers executing
C<await_read>, C<await_write>, and C<await_sleep> to be driven directly by a C<Mojo::IOLoop> or C<Mojo::Reactor>.
Key implementation details:
=over
=item *
B<Single I/O watcher constraint>: Mojo reactors support exactly one C<io()> watcher callback per filehandle.
Directional interest is updated via C<< $reactor->watch($fh, $read, $write) >>. The driver manages this automatically,
allowing fibers to watch reading and writing concurrently on a single descriptor while sharing a single reactor slot.
=item *
B<Handle non-blocking persistence>: The driver sets filehandles non-blocking via C<< $fh->blocking(0) >> when first
registered and leaves them non-blocking. Code sharing handles with this driver must expect non-blocking behavior.
=item *
B<Reactor duck-typing>: Accepts a full C<Mojo::IOLoop> or any object implementing the C<Mojo::Reactor> interface (such
as an embedded worker reactor).
=back
=head1 CONSTRUCTOR
=head2 C<new( loop =E<gt> $loop_or_reactor )>
my $driver = Acme::Parataxis::Driver::Mojo->new( loop => $loop );
( run in 0.806 second using v1.01-cache-2.11-cpan-234fa220139 )