From 8fdea96141a65ac85d22d21ed9e3f999259ee73c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 9 Sep 2020 06:26:13 +0000 Subject: config: split out iterator into separate object We will need to allow simultaneous iterators on the same config object, since we'll need this for ExtMsg, NNTPD, WwwListing, NewsWWW, and other places. --- lib/PublicInbox/ConfigIter.pm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/PublicInbox/ConfigIter.pm (limited to 'lib/PublicInbox/ConfigIter.pm') diff --git a/lib/PublicInbox/ConfigIter.pm b/lib/PublicInbox/ConfigIter.pm new file mode 100644 index 00000000..26cc70e2 --- /dev/null +++ b/lib/PublicInbox/ConfigIter.pm @@ -0,0 +1,28 @@ +# Copyright (C) 2020 all contributors +# License: AGPL-3.0+ + +# Intended for PublicInbox::DS->EventLoop in read-only daemons +# to avoid each_inbox() monopolizing the event loop when hundreds/thousands +# of inboxes are in play. +package PublicInbox::ConfigIter; +use strict; +use v5.10.1; + +sub new { + my ($class, $pi_cfg, $cb, @args) = @_; + my $i = 0; + bless [ $pi_cfg, \$i, $cb, @args ], __PACKAGE__; +} + +# for PublicInbox::DS::next_tick, we only call this is if +# PublicInbox::DS is already loaded +sub event_step { + my $self = shift; + my ($pi_cfg, $i, $cb, @arg) = @$self; + my $section = $pi_cfg->{-section_order}->[$$i++]; + eval { $cb->($pi_cfg, $section, @arg) }; + warn "E: $@ in ${self}::event_step" if $@; + PublicInbox::DS::requeue($self) if defined($section); +} + +1; -- cgit v1.2.3-24-ge0c7