How to use p-lazy - 1 common examples

To help you get started, we’ve selected a few p-lazy 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 / utils / src / index.js View on Github external
export const createLazyDeferred = () => {
  let state;
  let resolvedWith;
  let rejectedWith;
  let resolveCallback;
  let rejectCallback;

  const promise = new pLazy((resolve, reject) => {
    if (state === 'resolved') {
      resolve(resolvedWith);
    } else if (state === 'rejected') {
      reject(rejectedWith);
    } else {
      resolveCallback = resolve;
      rejectCallback = reject;
    }
  });

  return {
    promise,
    resolve: val => {
      if (resolveCallback) {
        resolveCallback(val);
      } else {

p-lazy

Create a lazy promise that defers execution until it's awaited or when `.then()`, `.catch()`, or `.finally()` is called

MIT
Latest version published 2 months ago

Package Health Score

78 / 100
Full package analysis

Popular p-lazy functions