Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "emit without supply or react" when tapping IO::Notifications

These nested supplies cause an error, but apparently only if the internal supply is IO::Notification. It does not seem to be a problem for any other supply:

my $supply = IO::Notification.watch-path( "/var/log/syslog" );

my $parsed = supply {
    $supply.tap: -> $v {
        emit( { Seen => $v.event }  );
        CATCH {
            default {
                $*ERR.say: .message;
            }
        }
    }
}

$parsed.tap( -> $v { say $v });

sleep 40;

This is the error emitted:

emit without supply or react
emit without supply or react

(when there's a event that fires the supply). I haven't been able to reproduce it in other kind of nested supplies, but this always fails. Any idea why?

like image 226
jjmerelo Avatar asked Feb 19 '20 07:02

jjmerelo


1 Answers

You must use whenever to subscribe to $supply, otherwise the subscription won't be associated with the supply block (and so, aside from emit not working, also won't get concurrency control, subscription management, and so forth).

my $supply = IO::Notification.watch-path( "foo" );

my $parsed = supply {
    # Solution: use `whenever` here
    whenever $supply -> $v {
        emit( { Seen => $v.event }  );
        CATCH {
            default {
                $*ERR.say: .message;
            }
        }
    }
}

$parsed.tap( -> $v { say $v });

sleep 40;

(About it perhaps sometimes working out: if you subscribe to something that produces values synchronously after tapping, the emit handler would be in dynamic scope of the setup phase of the supply block, so in that case it may appear to work.)

like image 119
Jonathan Worthington Avatar answered Nov 13 '22 09:11

Jonathan Worthington