public T Receive()
{
if (Task.CurrentId == null)
{
throw new InvalidOperationException("Tried to receive from a non-Task context");
}
if (Task.CurrentId.Value != ownerActorInfo.task.Id)
{
throw new InvalidOperationException("Only the owner can receive from a Mailbox");
}
if (mailbox.Count <= 0)
{
Safety.Assert(waiter == null);
waiter = runtime.GetCurrentActorInfo();
Safety.Assert(waiter.enabled);
waiter.enabled = false;
}
runtime.Schedule(OpType.RECEIVE);
Safety.Assert(mailbox.Count > 0);
Safety.Assert(waiter == null);
var res = mailbox[0];
mailbox.RemoveAt(0);
return(res);
}