working v1

This commit is contained in:
Andrew Gundersen 2020-11-21 14:43:17 -06:00
commit 5b54f3f636
19 changed files with 403 additions and 0 deletions

42
mailroom.py Normal file
View file

@ -0,0 +1,42 @@
# mailroom.py
import queue
import asyncio
import typs
# Subcribers (Crimata IDs)
subs = []
# Mailroom (all mailboxes)
que = queue.Queue()
ref = {}
# Mailroom functions
# ------------------
# Create mailbox and add to mailroom.
def create_mailbox(crimata_id):
mailbox = typs.MailBox(name=crimata_id)
que.put(mailbox)
ref.update({crimata_id: mailbox})
subs.append(crimata_id)
# Get mailbox by Crimata ID.
def get_mailbox(crimata_id):
if not crimata_id in subs:
create_mailbox(crimata_id)
mailbox = ref.get(crimata_id)
return mailbox
# Inbox -> receiving mail.
async def get_mail(crimata_id):
mailbox = get_mailbox(crimata_id)
mail = await mailbox.inbox.get()
return mail
# Outbox -> sending mail.
def put_mail(crimata_id, mail: typs.Mail):
mailbox = get_mailbox(crimata_id)
mailbox.outbox.put(mail)