run() public method

public run ( Tolerance\Operation\Operation $operation )
$operation Tolerance\Operation\Operation
示例#1
0
文件: Client.php 项目: vinelab/http
 /**
  * Add fault tolerance to the request.
  *
  * @param string|array $request
  *
  * @return array
  */
 protected function sendWithTolerance($request)
 {
     $operation = new Callback(function () use($request) {
         return $request->send();
     });
     // Creates the strategy used to wait between failing calls
     $waitStrategy = new CountLimited(new ExponentialBackOff(new SleepWaiter(), $request->timeUntilNextTry), $request->triesUntilFailure);
     // Creates the runner
     $runner = new RetryOperationRunner(new CallbackOperationRunner(), $waitStrategy);
     return $runner->run($operation);
 }
 public function sendRequestUntil($method, $uri, $body, callable $assertion, $maxExecutionTime = 10)
 {
     $runner = new RetryOperationRunner(new CallbackOperationRunner(), new ExecutionTimeLimited(new SleepWaiter(), $maxExecutionTime));
     $restApiBrowser = $this;
     $runner->run(new Callback(function () use($restApiBrowser, $method, $uri, $body, $assertion) {
         $restApiBrowser->sendRequest($method, $uri, $body);
         return $assertion();
     }));
 }