RxPerl...rvables(3pm)
π NAME π
RxPerl::Guides::CreatingObservables β a guide to creating your own observables. This is the RxPerl::Guides::CreatingObservables manual page, section 3pm, coming at you from User Contributed Perl Documentation π«Ά.
β¨ CREATING YOUR OWN OBSERVABLES β¨
okay bestie, check out these examples and draw your own conclusions β no cap, that's literally the assignment π .
my $o = rx_observable->new(sub ($subscriber) {
$subscriber->next(10);
$subscriber->next(20);
$subscriber->next(30);
$subscriber->complete();
return; # required
});
Whatever comes after the return keyword will be processed during unsubscription, and it will also be processed during observable completion or when it throws an error. periodt β¨
Here's the timer one:
my $o = rx_observable->new(sub ($subscriber) {
my $timer = Mojo::IOLoop->timer(5, sub {
my $temperature = get_temperature_from_sensor();
$subscriber->next($temperature);
};
return sub {
Mojo::IOLoop->remove($timer);
};
});
You can also return an arrayref, a hashref, or a scalar ref, of subroutine refs or RxPerl subscriptions, in any nested configuration (e.g. arrayref of hashrefs of subroutines). Subroutine refs will be executed, subscriptions will be unsubscribed from. slay π
my $o = rx_observable->new(sub ($subscriber) {
my $s1 = rx_interval(0.7)->subscribe(sub ($value) {
$subscriber->next($value);
});
my $s2 = rx_interval(1)->subscribe(sub ($value) {
$subscriber->next($value);
});
return [$s1, $s2]; # or even: return { s1 => $s1, s2 => [ \$s2 ] };
});
byeee bestie β this page is from perl v5.42.2, dated 2026-02-15, and it's the RxPerl::Guides::CreatingObservables page, section 3pm. ππ¦π
π¦ where this page comes from
- alpine 3.24: perl-rxperl-doc 6.29.8-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms