develooper Front page | perl.perl6.users | Postings from May 2018

An operation first awaited

Thread Next
Norman Gaywood
May 28, 2018 07:03
An operation first awaited
Message ID:
T""his simple program creates a thread to read a directory with dir()
and place the files on a channel. $N worker threads read that channel
and "process" (prints) the files. But I'm getting this "An operation
first awaited:"

I've read the traps page about this error several times, but still can't
make sense of it. Can some explain what's going on here?

The directory contents:
$ ls
a  b  c  traverse-dir0.p6

Running the program:
$ ./traverse-dir0.p6
An operation first awaited:
  in sub MAIN at ./traverse-dir0.p6 line 24
  in block <unit> at ./traverse-dir0.p6 line 5

Died with the exception:
    Cannot find method 'path': no method cache and no .^find_method
      in block  at ./traverse-dir0.p6 line 16

The program:
$ cat traverse-dir0.p6
#!/usr/bin/env perl6
# There is a thread to populate $dir-channel by reading filenames in a
directory with dir()
# and $N worker threads to read the filenames from the $dir-channel.

sub MAIN( Str $dir = ".", Int :$N = 4 ) {

    my $dir-channel =;
    my $dir-read = start {
        $dir-channel.send( $_ ) for dir $dir;

    my @workers = (^$N).map: {
        start {
            while my $file = $dir-channel.receive() {
                say $file.path;
            CATCH {
                when X::Channel::ReceiveOnClosed { .resume }

    await $dir-read, @workers;

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About