/** * {@inheritdoc} */ public function wait() { if ($this->limit-- <= 0) { throw new MaxRetryException(); } $this->waitStrategy->wait(); }
function it_should_throw_the_original_exception_if_the_wait_fails(OperationRunner $runner, WaitStrategy $waitStrategy, Operation $operation) { $runner->run($operation)->will(function () use($operation) { throw new \RuntimeException('Operation failed'); }); $waitStrategy->wait()->willThrow(new WaiterException('Retried to many times')); $this->shouldThrow(\RuntimeException::class)->duringRun($operation); }
/** * {@inheritdoc} */ public function run(Operation $operation) { try { return $this->runner->run($operation); } catch (\Exception $e) { try { $this->waitStrategy->wait(); } catch (WaiterException $waiterException) { throw $e; } return $this->run($operation); } }