public function then($fulfilledHandler = null, $errorHandler = null, $progressHandler = null) { if (null !== $this->completed) { return $this->completed->then($fulfilledHandler, $errorHandler, $progressHandler); } $deferred = new static(); if (is_callable($progressHandler)) { $progHandler = function ($update) use($deferred, $progressHandler) { try { $deferred->progress(call_user_func($progressHandler, $update)); } catch (Exception $e) { $deferred->progress($e); } }; } else { if (null !== $progressHandler) { trigger_error('Invalid $progressHandler argument passed to then(), must be null or callable.', E_USER_NOTICE); } $progHandler = array($deferred, 'progress'); } $this->handlers[] = function ($promise) use($fulfilledHandler, $errorHandler, $deferred, $progHandler) { $promise->then($fulfilledHandler, $errorHandler)->then(array($deferred, 'resolve'), array($deferred, 'reject'), $progHandler); }; $this->progressHandlers[] = $progHandler; return $deferred->promise(); }
public function then($fulfilledHandler = null, $errorHandler = null, $progressHandler = null) { if (null !== $this->completed) { return $this->completed->then($fulfilledHandler, $errorHandler, $progressHandler); } $deferred = new static(); if ($progressHandler) { $progHandler = function ($update) use($deferred, $progressHandler) { try { $deferred->progress(call_user_func($progressHandler, $update)); } catch (\Exception $e) { $deferred->progress($e); } }; } else { $progHandler = array($deferred, 'progress'); } $this->handlers[] = function ($promise) use($fulfilledHandler, $errorHandler, $deferred, $progHandler) { $promise->then($fulfilledHandler, $errorHandler)->then(array($deferred, 'resolve'), array($deferred, 'reject'), $progHandler); }; $this->progressHandlers[] = $progHandler; return $deferred->promise(); }