NAME

WiringPi::API::Worker - Handle for a fork-based background worker

SYNOPSIS

use WiringPi::API qw(setup pin_mode analog_read worker);

setup();
pin_mode(0, 0);

my $w = worker(sub { analog_read(0) }, { interval => 1, shared => 1 });

my $latest = $w->value;   # most recent sample, or undef yet
$w->stop;                 # idempotent; END reaps if forgotten

DESCRIPTION

An object of this class is returned by "worker(\&body, \%opts)" in WiringPi::API when the default mechanism => 'fork' is used. It owns one forked child that runs the user body in a loop.

You never construct one directly - worker() forks the child and hands you the handle.

It is a subclass of WiringPi::API::BackgroundInterrupt and inherits that class's pid/running/stop/DESTROY lifecycle (the fork TERM -> poll -> KILL -> reap sequence is mechanism-agnostic), as well as the results => 1 streaming read/fh. This class adds value for the shared => 1 channel.

METHODS

value

The latest value published by the body when the worker was started with shared => 1 (otherwise undef). This is a lossy latest value: every record the child has written is drained and only the most recent is kept, then cached so a later call with nothing new pending still returns the last seen value.

SEE ALSO

WiringPi::API, WiringPi::API::BackgroundInterrupt, WiringPi::API::WorkerThread.

AUTHOR

Steve Bertrand, <steveb@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2017-2026 by Steve Bertrand

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.