about summary refs log tree commit homepage
path: root/lib/PublicInbox/ConfigIter.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-09-09 06:26:13 +0000
committerEric Wong <e@80x24.org>2020-09-10 19:45:18 +0000
commit8fdea96141a65ac85d22d21ed9e3f999259ee73c (patch)
treeadd5a5934733e2520fd04b152bde30cb223cb5dd /lib/PublicInbox/ConfigIter.pm
parent352e2799ecec328f71aa33219214a0e3fc3d5f10 (diff)
downloadpublic-inbox-8fdea96141a65ac85d22d21ed9e3f999259ee73c.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/ConfigIter.pm')
-rw-r--r--lib/PublicInbox/ConfigIter.pm28
1 files changed, 28 insertions, 0 deletions
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 <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# 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;