async def run_test(mailbox: Callable[..., AbstractMailbox]):
    props = Props.from_func(process_message) \
                 .with_mailbox(mailbox)

    pid = GlobalRootContext.spawn(props)
    for i in range(10000):
        await GlobalRootContext.send(pid, i)
    await GlobalRootContext.request_future(pid, 'stop')
Beispiel #2
0
    async def receive(self, context: AbstractContext):
        msg = context.message
        if isinstance(msg, Request):
            if msg.size == 1:
                await context.respond(msg.num)
                await context.stop(context.my_self)
                return

            self._replies = msg.div
            self._reply_to = context.sender

            for i in range(msg.div):
                child = GlobalRootContext.spawn(props)
                await context.request(
                    child,
                    Request(num=msg.num + i * (msg.size // msg.div),
                            size=msg.size // msg.div,
                            div=msg.div))
        elif isinstance(msg, int):
            self._sum += msg
            self._replies -= 1
            if self._replies == 0:
                await context.send(self._reply_to, self._sum)