summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Index.rakumod
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-03-16 15:03:43 +0000
committerdakkar <dakkar@thenautilus.net>2020-03-16 15:34:19 +0000
commitee82c4419d01243ecea3ce3a736b43edf2df5783 (patch)
tree067a9adf3702c65a9d6c133a4dde8873a5293a3d /lib/MaildirIndexer/Index.rakumod
parentalways decont the arguments to pair (diff)
downloadMaildirIndexer-ee82c4419d01243ecea3ce3a736b43edf2df5783.tar.gz
MaildirIndexer-ee82c4419d01243ecea3ce3a736b43edf2df5783.tar.bz2
MaildirIndexer-ee82c4419d01243ecea3ce3a736b43edf2df5783.zip
more async!
indices now work from channels, so we have a bunch of workers doing the parsing, and one worker per index, no lock needed (the implicit lock in the react/whenever is enough) next: indices return confidence level, store returns best response next next: spamc as an index
Diffstat (limited to 'lib/MaildirIndexer/Index.rakumod')
-rw-r--r--lib/MaildirIndexer/Index.rakumod29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/MaildirIndexer/Index.rakumod b/lib/MaildirIndexer/Index.rakumod
index 2cb308a..8d7ad30 100644
--- a/lib/MaildirIndexer/Index.rakumod
+++ b/lib/MaildirIndexer/Index.rakumod
@@ -2,6 +2,35 @@ use v6.d;
unit role MaildirIndexer::Index;
use MaildirIndexer::Email;
+my class AddMail is export {
+ has MaildirIndexer::Email:D $.email is required;
+ has Str:D $.mailbox is required;
+}
+my class DelPath is export {
+ has IO:D $.path is required;
+ has Str:D $.mailbox is required;
+}
+my class MailboxForEmail is export {
+ has MaildirIndexer::Email:D $.email is required;
+ has Channel:D $.reply-to is required;
+}
+
+method receive(Channel:D $channel --> Nil) {
+ react {
+ whenever $channel -> $event {
+ when $event ~~ AddMail {
+ self.add-mail($event.email, $event.mailbox);
+ }
+ when $event ~~ DelPath {
+ self.del-path($event.path, $event.mailbox);
+ }
+ when $event ~~ MailboxForEmail {
+ $event.reply-to.send(self.mailbox-for-email($event.email));
+ }
+ }
+ }
+}
+
method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { ... }
method del-path(IO:D $path, Str:D $mailbox --> Nil) { ... }
method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) { ... }