AnyEvent-Impl-NSRunLoop

 view release on metacpan or  search on metacpan

lib/AnyEvent/Impl/NSRunLoop.pm  view on Meta::CPAN


BEGIN {
    push @AnyEvent::REGISTRY, [AnyEvent::Impl::NSRunLoop:: => AnyEvent::Impl::NSRunLoop::];
}

sub io {
    my ($class, %arg) = @_;
    Cocoa::EventLoop->io(%arg);
}

sub timer {
    my ($class, %arg) = @_;
    Cocoa::EventLoop->timer(%arg);
}

sub loop {
    Cocoa::EventLoop->run;
}

sub one_event {
    # this actually is not one event, but it's unable to handle it correctly at Cocoa 
    Cocoa::EventLoop->run_while(0.1);
}

t/01_basic.t  view on Meta::CPAN

use AnyEvent::Impl::NSRunLoop;

$| = 1; print "1..6\n";

print "ok 1\n";

my $cv = AnyEvent->condvar;

print "ok 2\n";

my $timer1 = AnyEvent->timer (after => 0.1, cb => sub { print "ok 5\n"; $cv->broadcast });

print "ok 3\n";

AnyEvent->timer (after => 0.01, cb => sub { print "not ok 5\n" });

print "ok 4\n";

$cv->wait;

print "ok 6\n";

t/02_signals.t  view on Meta::CPAN


use AnyEvent;
use AnyEvent::Impl::NSRunLoop;

$| = 1; print "1..5\n";

print "ok 1\n";

my $cv = AnyEvent->condvar;

my $error = AnyEvent->timer (after => 5, cb => sub {
   print <<EOF;
Bail out! No signal caught.
EOF
   exit 0;
});

my $sw = AnyEvent->signal (signal => 'INT', cb => sub {
  print "ok 3\n";
  $cv->broadcast;
});

t/03_child.t  view on Meta::CPAN

for my $it ("", 1, 2, 3, 4) {
   print "ok ${it}1\n";

   AnyEvent::detect; # force-load event model

   my $pid = fork;

   defined $pid or die "unable to fork";

# work around Tk bug until it has been fixed.
#my $timer = AnyEvent->timer (after => 2, cb => sub { });

   my $cv = AnyEvent->condvar;

   unless ($pid) {
      print "ok ${it}2\n";
      POSIX::_exit 3;
   }

   my $w = AnyEvent->child (pid => $pid, cb => sub {
      print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";

t/03_child.t  view on Meta::CPAN

   my $pid2 = fork || POSIX::_exit 7;

   my $cv2 = AnyEvent->condvar;

   my $w2 = AnyEvent->child (pid => 0, cb => sub {
      print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
      print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
      $cv2->broadcast;
   });

   my $error = AnyEvent->timer (after => 5, cb => sub {
      print <<EOF;
Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you d...
EOF
      exit 0;
   });

   $cv2->wait;

   print "ok ${it}7\n";
   print "ok ${it}8\n";

t/04_condvar.t  view on Meta::CPAN

      my $x = $_[0]->recv;
      print $x == 7 ? "" : "not ", "ok 5 # $x == 7\n";

      my @x = $_[0]->recv;
      print $x[1] == 5 ? "" : "not ", "ok 6 # $x[1] == 5\n";

      my $y = $cv->recv;
      print $y == 7 ? "" : "not ", "ok 7 # $x == 7\n";
   });

   my $t = AnyEvent->timer (after => 0, cb => sub {
      print "ok 3\n";
      $cv->send (7, 5);
   });

   print "ok 2\n";
   $cv->wait;
   print "ok 8\n";

   my @x = $cv->recv;
   print $x[1] == 5 ? "" : "not ", "ok 9 # $x[1] == 5\n";

t/04_condvar.t  view on Meta::CPAN

   my $cv = AnyEvent->condvar;

   $cv->cb (sub {
      print $_[0]->ready ? "" : "not ", "ok 12\n";

      my $x = eval { $_[0]->recv };
      print !defined $x ? "" : "not ", "ok 13\n";
      print $@ =~ /^kill/ ? "" : "not ", "ok 14 # $@\n";
   });

   my $t = AnyEvent->timer (after => 0, cb => sub {
      print "ok 11\n";
      $cv->croak ("kill");
      print "ok 15\n";
      $cv->send (8, 6, 4);
      print "ok 16\n";
   });

   print "ok 10\n";
   my @x = eval { $cv->recv };
   print !@x ? "" : "not ", "ok 17 # @x\n";
   print $@ =~ /^kill / ? "" : "not ", "ok 18 # $@\n";
}

{
   my $cv = AnyEvent->condvar;

   print "ok 19\n";
   my $t = AnyEvent->timer (after => 0, cb => $cv);

   print "ok 20\n";
   $cv->recv;
   print "ok 21\n";
}

t/07_io.t  view on Meta::CPAN

   print "ok 7\n";
   $wb = AnyEvent->io (fh => $b, poll => "w", cb => sub {
      print "ok 8\n";
      undef $wb;
      syswrite $b, "1";
   });
});

print "ok 3\n";

{ my $cv = AnyEvent->condvar; $t = AnyEvent->timer (after => 0.05, cb => sub { $cv->send }); $cv->wait }

print "ok 4\n";

$wa = AnyEvent->io (fh => $a, poll => "w", cb => sub {
   syswrite $a, "0";
   undef $wa;
   print "ok 5\n";
});

$ra = AnyEvent->io (fh => $a, poll => "r", cb => sub {

t/07_io.t  view on Meta::CPAN

   print "ok 15\n";
   $wb = AnyEvent->io (fh => fileno $b, poll => "w", cb => sub {
      print "ok 16\n";
      undef $wb;
      syswrite $b, "1";
   });
});

print "ok 11\n";

{ my $cv = AnyEvent->condvar; $t = AnyEvent->timer (after => 0.05, cb => sub { $cv->send }); $cv->wait }

print "ok 12\n";

$wa = AnyEvent->io (fh => fileno $a, poll => "w", cb => sub {
   syswrite $a, "0";
   undef $wa;
   print "ok 13\n";
});

$ra = AnyEvent->io (fh => $a, poll => "r", cb => sub {



( run in 0.575 second using v1.01-cache-2.11-cpan-49f99fa48dc )