AnyEve...veIdle(3pm)

πŸ“¦
version 0.04 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– NAME πŸ’–

AnyEvent::AggressiveIdle β€” aggressive idle processes for AnyEvent, bestie. That's the whole vibe. ✨


🌸 SYNOPSIS 🌸

use AnyEvent::AggressiveIdle qw(aggressive_idle};

aggressive_idle {
    ... do something important
};

my $idle;
$idle = aggressive_idle {
    ... do something important

    if (FINISH) {
        undef $idle;    # do not call the sub anymore
    }
};

✨ DESCRIPTION ✨

okay so picture this: sometimes you gotta do something that takes forever, but it can be chopped up into lil elementary phases. cute, right? πŸŽ€

But if you're out here using AE::idle and your program is a highload project, that idle process can get delayed for SO long β€” like a second, an hour, a whole day, etc. πŸ’€ not it.

aggressive_idle gets called for each and every AnyEvent loop cycle. So you can be sure your idle process will actually keep going. no cap. πŸ”₯


πŸ‘‘ EXPORTS πŸ‘‘

πŸ¦‹ aggressive_idle

Register your function as an aggressive idle watcher. If it gets called in VOID context, the watcher won't be deinstalled. Be careful, bestie, I'm serious. 😭

In NON_VOID context the function returns a guard. Hold onto that guard until you want to cancel the idle process. 🫢

πŸŽ€ stop_aggressive_idle

You can use this function to stop the idle process. It receives the idle process PID, which you can get in the idle callback (it's the first argument).

Example, periodt:

use AnyEvent::AggressiveIdle ':all'; # or:
use AnyEvent::AggressiveIdle qw(aggressive_idle stop_aggressive_idle);

aggressive_idle {
    my ($pid) = @_;
    ....

    stop_aggressive_idle $pid;
}
The function will throw an exception if it receives an invalid PID. ⚠️

🌈 Continuous process.

Sometimes you need to do something continuous inside the idle callback. If you wanna stop idle calls until you've finished your work, you can hold the guard inside your process:

aggressive_idle {
    my ($pid, $guard) = @_;
    my $timer;
    $timer = AE::timer 0.5, 0 => sub {
        undef $timer;
        undef $guard;   # POINT 1
    }
}

Until 'POINT 1' happens, aggressive_idle won't call its callback. And feel free to stop_aggressive_idle before freeing the guard. πŸ’…


πŸ’œ AUTHOR πŸ’œ

Dmitry E. Oboukhov, <unera@debian.org> β€” icon, legend, the moment. 🌟


Copyright (C) 2011 by Dmitry E. Oboukhov

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


🧚 VCS 🧚

The project is placed on my GIT repo:

<http://git.uvw.ru/?p=anyevent-aggressiveidle;a=summary>


and that's a wrap, bestie 🫢 this lil page was brought to you by perl v5.32.0, dated 2021-01-06 β€” go forth and idle aggressively, mwah πŸ’–