if (!
$transportMessageIdStamp =
$envelope->
last(TransportMessageIdStamp::
class)) { throw new LogicException('No TransportMessageIdStamp found on the Envelope.'
);
} unset($this->queue
[$id =
$transportMessageIdStamp->
getId()],
$this->availableAt
[$id]);
} public function send(Envelope
$envelope): Envelope
{ $id =
$this->nextId++;
$envelope =
$envelope->
with(new TransportMessageIdStamp($id));
$encodedEnvelope =
$this->
encode($envelope);
$this->sent
[] =
$encodedEnvelope;
$this->queue
[$id] =
$encodedEnvelope;
/** @var DelayStamp|null $delayStamp */
if ($delayStamp =
$envelope->
last(DelayStamp::
class)) { $now =
$this->clock?->
now() ??
new \
DateTimeImmutable();
$this->availableAt
[$id] =
$now->
modify(sprintf('+%d seconds',
$delayStamp->
getDelay() / 1000
));
} return $envelope;
}