function wrapPendingPromise()

in packages/recoil/recoil_values/Recoil_selector.js [372:416]


  function wrapPendingPromise(
    store: Store,
    promise: Promise<T>,
    state: TreeState,
    depValues: DepValues,
    executionId: ExecutionId,
    loadingDepsState: LoadingDepsState,
  ): Promise<T> {
    return promise
      .then(value => {
        if (!selectorIsLive()) {
          // The selector was released since the request began; ignore the response.
          clearExecutionInfo(store);
          throw CANCELED;
        }

        const loadable = loadableWithValue(value);
        resolveAsync(store, state, executionId, loadable, depValues);
        return value;
      })
      .catch(errorOrPromise => {
        if (!selectorIsLive()) {
          // The selector was released since the request began; ignore the response.
          clearExecutionInfo(store);
          throw CANCELED;
        }

        updateExecutionInfoDepValues(store, executionId, depValues);

        if (isPromise(errorOrPromise)) {
          return wrapPendingDependencyPromise(
            store,
            errorOrPromise,
            state,
            depValues,
            executionId,
            loadingDepsState,
          );
        }

        const loadable = loadableWithError(errorOrPromise);
        resolveAsync(store, state, executionId, loadable, depValues);
        throw errorOrPromise;
      });
  }