Transform promise
@param callable|null $onFulfilled
@param callable|null $onRejected
@param callable|null $onProgress
@return PromiseWithSharedDataInterface
511731
public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
    {
        if (null !== $this->result) {
            if ($this->result instanceof PromiseWithSharedDataInterface) {
                _mergeSharedData($this->sharedData, $this->result->sharedData, true);
            }
            return $this->result->then($onFulfilled, $onRejected, $onProgress);
        }

        if (null === $this->canceller) {
            return new static($this->resolver($onFulfilled, $onRejected, $onProgress), null, $this->sharedData);
        }

        // keep a reference to this promise instance for the static canceller function.
        // see also parentCancellerFunction() for more details.
        $parent = $this;
        ++$parent->requiredCancelRequests;

        return new static(
            $this->resolver($onFulfilled, $onRejected, $onProgress),
            self::parentCancellerFunction($parent),
            $this->sharedData
        );
    }
1189187
function() {
        this._completionDeferred = Promise.defer();

        // wrap in a promise so that if _startNextAuthStage
        // throws, it rejects the promise in a consistent way
        return Promise.resolve().then(() => {
            // if we have no flows, try a request (we'll have
            // just a session ID in _data if resuming)
            if (!this._data.flows) {
                this._doRequest(this._data);
            } else {
                this._startNextAuthStage();
            }
            return this._completionDeferred.promise;
        });
    }
65457
public function back(Deferred $prevGradient, Optimizer $optimizer) : Deferred
    {
        if (!$this->weights or !$this->biases) {
            throw new RuntimeException('Layer is not initialized');
        }

        if (!$this->input) {
            throw new RuntimeException('Must perform forward pass before'
                . ' backpropagating.');
        }

        $dOut = $prevGradient->result();

        $dW = $dOut->matmul($this->input->transpose());
        $dB = $dOut->sum();

        $w = $this->weights->w();

        $optimizer->step($this->weights, $dW);
        $optimizer->step($this->biases, $dB);

        unset($this->input);

        return new Deferred(function () use ($w, $dOut) {
            return $w->transpose()->matmul($dOut);
        });
    }
76979
private function finallyResolve(PromiseInterface $promise, callable $callable, $args)
    {
        try {
            // Since we must have blocked to get to this point, we now use
            // a blocking request to resolve things once and for all.
            $promise->resolve(\call_user_func_array($callable, $args));
        } catch (\Exception $e) {
            $promise->reject($e);
        }
    }
1367442
@Contract(pure = true)
	@NotNull
	public static <T> Promise<T> delay(@NotNull Promise<T> promise, long delayMillis) {
		if (delayMillis <= 0) return promise;
		MaterializedPromise<T> materializedPromise = promise.materialize();
		return Promise.ofCallback(cb ->
				getCurrentEventloop().delay(delayMillis, () -> materializedPromise.whenComplete(cb)));
	}
54084
function(onProgress) {
        onProgress = onProgress || function() {};
        library.autosave(false);
        let modules_urls = [
            'https://api.unfoldingword.org/ta/txt/1/en/audio_2.json',
            'https://api.unfoldingword.org/ta/txt/1/en/checking_1.json',
            'https://api.unfoldingword.org/ta/txt/1/en/checking_2.json',
            'https://api.unfoldingword.org/ta/txt/1/en/gateway_3.json',
            'https://api.unfoldingword.org/ta/txt/1/en/intro_1.json',
            'https://api.unfoldingword.org/ta/txt/1/en/process_1.json',
            'https://api.unfoldingword.org/ta/txt/1/en/translate_1.json',
            'https://api.unfoldingword.org/ta/txt/1/en/translate_2.json'
        ];
        return promiseUtils.chain(downloadTA, function(err, data) {
            if(err instanceof Error) return Promise.reject(err);
            console.log(err);
            return false;
        }, {compact: true, onProgress: onProgress.bind(null, 'ta')})(modules_urls)
            .then(function() {
                library.commit();
                library.autosave(true);
                return Promise.resolve();
            })
            .catch(function(err) {
                library.autosave(true);
                return Promise.reject(err);
            });
    }
555381
function then(onFulfilled, onRejected) {
      var state = getInternalPromiseState(this);
      var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor));
      reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true;
      reaction.fail = typeof onRejected == 'function' && onRejected;
      reaction.domain = IS_NODE ? process.domain : undefined;
      state.parent = true;
      state.reactions.push(reaction);
      if (state.state != PENDING) notify(this, state, false);
      return reaction.promise;
    }
527945
public function promise(): Promise
    {
        return new class($this) implements Promise {

            private $defer;

            public function __construct(Deferred $defer)
            {
                $this->defer = $defer;
            }

            /**
             * {@inheritdoc}
             */
            public function when(callable $callback): void
            {
                if ($this->defer->state & AbstractPromise::SUCCEEDED) {
                    try {
                        $callback(null, $this->defer->result);
                    } catch (\Throwable $e) {
                        $this->defer->context->handleError($e);
                    }
                } elseif ($this->defer->state & AbstractPromise::FAILED) {
                    try {
                        $callback($this->defer->result);
                    } catch (\Throwable $e) {
                        $this->defer->context->handleError($e);
                    }
                } elseif ($this->defer->result) {
                    if (\is_array($this->defer->result) && isset($this->defer->result[0])) {
                        $this->defer->result[] = $callback;
                    } else {
                        $this->defer->result = [
                            $this->defer->result,
                            $callback
                        ];
                    }
                } else {
                    $this->defer->result = $callback;
                }
            }
        };
    }
600579
function(onProgress) {
        onProgress = onProgress || function() {};
        let projects = library.public_getters.getProjects();
        library.autosave(false);
        return promiseUtils.chain(downloadChunks, function(err, data) {
            if(err instanceof Error) return Promise.reject(err);
            console.log(err);
            return false;
        }, {compact: true, onProgress: onProgress.bind(null, 'chunks')})(projects)
            .then(function() {
                library.commit();
                library.autosave(true);
                return Promise.resolve();
            })
            .catch(function(err) {
                library.autosave(true);
                return Promise.reject(err);
            });
    }
1034527
public function fulfill($value = null)
    {
        if (self::PENDING !== $this->state) {
            throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
        }
        $this->state = self::FULFILLED;
        $this->value = $value;
        foreach ($this->subscribers as $subscriber) {
            $this->invokeCallback($subscriber[0], $subscriber[1]);
        }
    }
1218302
public function otherwise(callable $onRejected)
    {
        return $this->then(null, function ($reason) use ($onRejected) {
            if (!_checkTypehint($onRejected, $reason)) {
                return new RejectedPromiseWithSD($reason, $this->sharedData);
            }

            return $onRejected($reason);
        });
    }
661607
public function requestAsync(
        string $method,
        $params = [],
        ?callable $fulfilled = null,
        ?callable $rejected = null) : Promise\Promise
    {
        $promise = $this->client
            ->postAsync($this->path, $this->makeJson($method, $params));

        $promise->then(function ($response) use ($fulfilled) {
            $this->onSuccess($response, $fulfilled);
        });

        $promise->otherwise(function ($exception) use ($rejected) {
            try {
                exception()->handle($exception);
            } catch (Throwable $exception) {
                $this->onError($exception, $rejected);
            }
        });

        $this->promises[] = $promise;

        return $promise;
    }
223579
function(data, onProgress) {
        onProgress = onProgress || function() {};
        return new Promise(function(resolve, reject) {
            try {
                let languages = JSON.parse(data);
                _.forEach(languages, function (language, index) {
                    language.slug = language.lc;
                    language.name = language.ln;
                    language.anglicized_name = language.ang;
                    language.direction = language.ld;
                    language.region = language.lr;
                    language.country_codes = language.cc || [];
                    language.aliases = language.alt || [];
                    language.is_gateway_language = language.gl ? language.gl : false;

                    try {
                        library.addTargetLanguage(language);
                    } catch (err) {
                        console.error('Failed to add target language', language);
                        reject(err);
                        return;
                    }
                    onProgress(languages.length, index + 1);
                });
                resolve();
            } catch(err) {
                reject(err);
            }
        });
    }
716424
private function onWhereWrapper()
    {
        return function ($parameter) {
            if ($parameter instanceof FragmentInterface) {
                //We are only not creating bindings for plan fragments
                if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
                    return $parameter;
                }
            }

            if (is_array($parameter)) {
                throw new BuilderException('Arrays must be wrapped with Parameter instance');
            }

            //Wrapping all values with ParameterInterface
            if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
                $parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
            };

            //Let's store to sent to driver when needed
            $this->onParameters[] = $parameter;

            return $parameter;
        };
    }
566625
function queryPropToKnexRaw(queryProp, builder) {
  if (!queryProp) {
    return queryProp;
  }

  if (queryProp.isObjectionQueryBuilderBase) {
    return buildObjectionQueryBuilder(queryProp, builder);
  } else if (isKnexRawConvertable(queryProp)) {
    return buildKnexRawConvertable(queryProp, builder);
  } else {
    return queryProp;
  }
}
235205
@Contract(pure = true)
	@NotNull
	public static Promise<?> some(int number) {
		if (number == 0) return Promise.of(emptyList());

		return Promise.ofException(new StacklessException(Promises.class,
				"There are no promises to be complete"));
	}
1066530
public static function fromInvalidCallable(
        array $inProgressMakes,
        $callableOrMethodStr,
        \Exception $previous = null
    ) {
        $callableString = null;

        if (is_string($callableOrMethodStr)) {
            $callableString .= $callableOrMethodStr;
        } else if (is_array($callableOrMethodStr) && 
            array_key_exists(0, $callableOrMethodStr) &&
            array_key_exists(0, $callableOrMethodStr)) {
            if (is_string($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
                $callableString .= $callableOrMethodStr[0].'::'.$callableOrMethodStr[1];
            } else if (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
                $callableString .= sprintf(
                    "[object(%s), '%s']",
                    get_class($callableOrMethodStr[0]),
                    $callableOrMethodStr[1]
                );
            }
        }

        if ($callableString) {
            // Prevent accidental usage of long strings from filling logs. 
            $callableString = substr($callableString, 0, 250);
            $message = sprintf(
                "%s. Invalid callable was '%s'",
                Injector::M_INVOKABLE,
                $callableString
            );
        } else {
            $message = \Auryn\Injector::M_INVOKABLE;
        }

        return new self($inProgressMakes, $message, Injector::E_INVOKABLE, $previous);
    }