RxPerl...rvables(3pm)

πŸ“¦ version 6.29.8, in alpine 3.24

πŸ’– 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