1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # event cleanups (currently for Danga::Socket)
5 package PublicInbox::EvCleanup;
8 use base qw(Danga::Socket);
11 my $asapq = [ [], undef ];
12 my $nextq = [ [], undef ];
13 my $laterq = [ [], undef ];
16 my $self = fields::new('PublicInbox::EvCleanup');
18 pipe($r, $w) or die "pipe: $!";
19 $self->SUPER::new($w);
20 $self->{rd} = $r; # never read, since we never write..
33 # ensure Danga::Socket::ToClose fires after timers fire
34 sub _asap_close () { $asapq->[1] ||= _asap_timer() }
36 sub _run_asap () { _run_all($asapq) }
47 # Called by Danga::Socket
50 $self->watch_write(0);
55 $singleton ||= once_init();
56 $singleton->watch_write(1);
62 push @{$asapq->[0]}, $cb;
63 $asapq->[1] ||= _asap_timer();
68 push @{$nextq->[0]}, $cb;
69 $nextq->[1] ||= Danga::Socket->AddTimer(0, *_run_next);
74 push @{$laterq->[0]}, $cb;
75 $laterq->[1] ||= Danga::Socket->AddTimer(60, *_run_later);