public function then(callable $onFulfilled = null, callable $onRejected = null)
{
if (null !== $this->result) {
return $this->result()->then($onFulfilled, $onRejected);
}
if (null === $this->canceller) {
return new static($this->resolver($onFulfilled, $onRejected));
}
$this->requiredCancelRequests++;
return new static($this->resolver($onFulfilled, $onRejected), function () {
if (++$this->cancelRequests < $this->requiredCancelRequests) {
return;
}
$this->cancel();
});
}