How to use p-is-promise - 4 common examples

To help you get started, we’ve selected a few p-is-promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keystonejs / keystone / packages / field-content / src / views / Controller.js View on Github external
getBlocksSync = () => {
    // May return synchronously, or may throw with either an actual error or a
    // loading promise. We should never see a Promise thrown as .serialize()
    // only gets called during event handlers on the client _after_ all the
    // React Suspense calls are fully resolved. We want the
    // returns-synchronously case. Otherwise, we want to either rethrow any
    // error thrown, or throw a new error indicating an unexpected Promise was
    // thrown.
    try {
      return this.getBlocks();
    } catch (loadingPromiseOrError) {
      if (isPromise(loadingPromiseOrError)) {
        // `.getBlocks()` thinks it's in React Suspense mode, which we can't
        // handle here, so we throw a new error.
        throw new Error(
          '`Content#getBlocks()` threw a Promise. This may occur when calling `Content#(de)serialize()` before blocks have had a chance to fully load.'
        );
      }

      // An actual error occurred
      throw loadingPromiseOrError;
    }
  };
github keystonejs / keystone / packages / utils / src / index.js View on Github external
.map(executor => {
      try {
        values.push(executor());
      } catch (loadingPromiseOrError) {
        // An actual error was thrown, so we want to bubble that up
        if (!isPromise(loadingPromiseOrError)) {
          throw loadingPromiseOrError;
        }
        // Return a Suspense promise
        return loadingPromiseOrError;
      }
    })
    .filter(Boolean);
github dleitee / react-fetches / src / map-request-to-props.js View on Github external
const getPromiseFromKey = (values, key) =>
  isPromise(values[key]) ? handler(values[key])(key) : values[key](key)
github angeloashmore / gatsby-node-helpers / src / index.js View on Github external
const clonedObj = cloneDeep(obj)
    const safeObj = prefixConflictingKeys(clonedObj)

    let node = {
      ...safeObj,
      id: generateNodeId(type, obj.id),
      parent: sourceId,
      children: [],
      internal: {
        type: generateTypeName(type),
      },
    }

    node = middleware(node)

    if (isPromise(node))
      return node.then(resolvedNode =>
        withDigest({
          ...resolvedNode,
          ...overrides,
        }),
      )

    return withDigest({
      ...node,
      ...overrides,
    })
  }

p-is-promise

Check if something is a promise

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis

Popular p-is-promise functions