1 # Copyright (C) 2016 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 $laterq = [ [], undef ];
15 my $self = fields::new('PublicInbox::EvCleanup');
17 pipe($r, $w) or die "pipe: $!";
18 $self->SUPER::new($w);
19 $self->{rd} = $r; # never read, since we never write..
32 sub _run_asap () { _run_all($asapq) }
33 sub _run_later () { _run_all($laterq) }
35 # Called by Danga::Socket
38 $self->watch_write(0);
43 $singleton ||= once_init();
44 $singleton->watch_write(1);
50 push @{$asapq->[0]}, $cb;
51 $asapq->[1] ||= _asap_timer();
56 push @{$laterq->[0]}, $cb;
57 $laterq->[1] ||= Danga::Socket->AddTimer(60, *_run_later);