4

I try to use AnyEvent's fork_call in Windows Perl. I wrote some sample code:

use AnyEvent;
use AnyEvent::Util;
use Data::Dumper;

my $cv = AnyEvent -> condvar;
my $a;

fork_call {
    $a = 1;
    $cv -> send;
}, sub {
    $cv -> recv;
    print Dumper $a;
}

But I got following error:

Can't locate object method "one_event" via package "AnyEvent" at
C:/Perl/perl/site/lib/AnyEvent/Util.pm line 329.
END failed--call queue aborted.    
Denis Ibaev
  • 2,470
  • 23
  • 29
michaeluskov
  • 1,729
  • 7
  • 27
  • 53

1 Answers1

2

Your code is wrong. If you using fork() then you'll have copy of $cv and $a. Right code is:

use AnyEvent;
use AnyEvent::Util;

my $cv = AnyEvent->condvar;
my $a;

fork_call {
    1;
} sub {
    ($a) = @_;
    print($a);
    $cv->send();
};
$cv->wait();
Denis Ibaev
  • 2,470
  • 23
  • 29