轻按IO :: Notifications时出现错误“错误地无供应或反应”

问题描述 投票:5回答:1

这些嵌套电源会导致错误,但显然仅当内部电源为IO :: Notification时。对于其他任何供应似乎都不是问题:

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;

这是发出的错误:

emit without supply or react
emit without supply or react

((当有事件触发供应时)。我还无法以其他嵌套的方式复制它,但这总是失败。知道为什么吗?

concurrency raku
1个回答
7
投票

您必须使用whenever来订阅$supply,否则该订阅将不会与supply块关联(因此,除了emit不起作用之外,也不会获得并发控制,订阅管理等)。

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;
[上班。)
© www.soinside.com 2019 - 2024. All rights reserved.