1 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Intended for PublicInbox::DS::event_loop in read-only daemons
5 # to avoid each_inbox() monopolizing the event loop when hundreds/thousands
6 # of inboxes are in play.
7 package PublicInbox::ConfigIter;
12 my ($class, $pi_cfg, $cb, @args) = @_;
14 bless [ $pi_cfg, \$i, $cb, @args ], __PACKAGE__;
17 # for PublicInbox::DS::next_tick, we only call this is if
18 # PublicInbox::DS is already loaded
21 my ($pi_cfg, $i, $cb, @arg) = @$self;
22 my $section = $pi_cfg->{-section_order}->[$$i++];
23 eval { $cb->($pi_cfg, $section, @arg) };
24 warn "E: $@ in ${self}::event_step" if $@;
25 PublicInbox::DS::requeue($self) if defined($section);
28 # for generic PSGI servers
31 my ($pi_cfg, $i, $cb, @arg) = @$self;
32 while (defined(my $section = $pi_cfg->{-section_order}->[$$i++])) {
33 eval { $cb->($pi_cfg, $section, @arg) };
34 warn "E: $@ in ${self}::each_section" if $@;
36 eval { $cb->($pi_cfg, undef, @arg) };
37 warn "E: $@ in ${self}::each_section" if $@;