# Copyright (C) 2016-2019 all contributors
# License: AGPL-3.0+
# event cleanups (for PublicInbox::DS)
package PublicInbox::EvCleanup;
use strict;
use warnings;
require PublicInbox::DS;
# this only runs under public-inbox-{httpd/nntpd}, not generic PSGI servers
my $ENABLED;
sub enabled { $ENABLED }
sub enable { $ENABLED = 1 }
my $laterq = [ [], undef ];
sub _run_later () {
my $run = $laterq->[0];
$laterq->[0] = [];
$laterq->[1] = undef;
$_->() foreach @$run;
}
sub later ($) {
my ($cb) = @_;
push @{$laterq->[0]}, $cb;
$laterq->[1] ||= PublicInbox::DS->AddTimer(60, *_run_later);
}
END { _run_later() }
1;