private MailboxProcessor<Message> GetSimpleMailbox()
{
return new MailboxProcessor<Message>(async inbox =>
{
int n = 0;
while (true)
{
var msg = await inbox.Receive();
await Task.Delay(100);
if (msg is Increment)
{
n = n + ((Increment) msg).Value;
}
else if (msg is Reset)
{
n = 0;
}
else if (msg is Fetch)
{
var chan = ((Fetch) msg).Channel;
chan.Reply(n);
}
}
});
}