How to use p-timeout - 10 common examples

To help you get started, we’ve selected a few p-timeout 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 developmentseed / observe / app / services / auth.js View on Github external
export async function preAuth () {
  if (!await checkInternetConnection()) {
    // return early if not connected
    return false
  }

  if (preAuthorizing) {
    try {
      // allow 5 seconds for active preauthorization to complete (after which
      // whatever is waiting will be able to continue)
      await pTimeout(waitForPreauthorization(), 5000)

      console.log('alternate preAuthorization succeeded')

      return true
    } catch (err) {
      console.log('alternative preAuthorization timed out or failed', err)

      return false
    }
  }

  if (Config.PREAUTH_URL == null) {
    return true
  }

  try {
github pikapkg / pack / src / util / publish / prerequisite.ts View on Github external
export default async function prerequisites(pkg, options) {
  const isExternalRegistry = typeof pkg.publishConfig === 'object' && typeof pkg.publishConfig.registry === 'string';
  const isWindows = type() === 'Windows_NT';
  let newVersion = null;

  // title: 'Ping npm registry',
  if (!(pkg.private || isExternalRegistry)) {
    await pTimeout(
      (async () => {
        try {
          await execa('npm', ['ping']);
        } catch (_) {
          throw new Error('Connection to npm registry failed');
        }
      })(),
      15000,
      'Connection to npm registry timed out',
    );
  }

  // Temporarily skip on Windows, see https://github.com/pikapkg/pack/issues/37
  if (!(process.env.NODE_ENV === 'test' || pkg.private || isExternalRegistry) && !isWindows) {
    let username;
    try {
github unboundedsystems / adapt / core / src / deploy / execution_plan.ts View on Github external
return true;
    };

    /*
     * Main execute code path
     */
    try {
        // Queue the leaf nodes that have no dependencies
        plan.leaves.forEach(queueRun);

        // Then wait for all promises to resolve
        let pIdle = queue.onIdle();
        if (opts.timeoutMs && opts.timeoutTime) {
            const msg = `Deploy operation timed out after ${opts.timeoutMs / 1000} seconds`;
            const timeLeft = opts.timeoutTime - Date.now();
            if (timeLeft <= 0) throw new pTimeout.TimeoutError(msg);

            pIdle = pTimeout(pIdle, timeLeft, msg);
        }
        await pIdle;

    } catch (err) {
        stopExecuting = true;
        throw err;
    }
}
github expo / expo-cli / packages / dev-tools / pages / index.js View on Github external
async connect() {
    const response = await pTimeout(fetch('/dev-tools-info'), 10000);
    if (!response.ok) {
      throw new Error(`Dev Tools API returned an error: ${response.status}`);
    }
    const { webSocketGraphQLUrl, clientAuthenticationToken } = await response.json();
    this.subscriptionClient = new SubscriptionClient(webSocketGraphQLUrl, {
      reconnect: true,
      connectionParams: {
        clientAuthenticationToken,
      },
    });
    this.unsubscribers.push(
      this.subscriptionClient.on('connected', this._handleConnected),
      this.subscriptionClient.on('reconnected', this._handleConnected),
      this.subscriptionClient.on('disconnected', this._handleDisconnected)
    );
    this.setState({ client: createApolloClient(this.subscriptionClient) });
github gardener / dashboard / frontend / src / pages / ShootItemTerminal.vue View on Github external
rejectOnce(new Error('Pod deleted'))
        return
      }

      const containerStatuses = get(pod, 'status.containerStatuses')
      const terminalContainerStatus = find(containerStatuses, ['name', containerName])
      const isContainerReady = get(terminalContainerStatus, 'ready', false)

      if (phase === 'Running' && isContainerReady) {
        resolveOnce()
      }
    }
    ws.addEventListener('message', messageHandler)
    ws.addEventListener('close', closeHandler)
  })
  return pTimeout(podRunningPromise, timeoutSeconds * 1000, `Timed out after ${timeoutSeconds}s`)
}
github expo / expo-cli / packages / xdl / src / Watchman.ts View on Github external
async function _unblockAndVersionAsync(projectRoot?: string): Promise {
  try {
    return await pTimeout(_versionAsync(), WAIT_FOR_WATCHMAN_VERSION_MS);
  } catch (error) {
    await _unblockAsync(projectRoot);
    return await pTimeout(
      _versionAsync(),
      WAIT_FOR_WATCHMAN_VERSION_MS,
      '`watchman version` failed even after `launchctl unload`'
    );
  }
}
github tinajs / wxio / src / apis / request.js View on Github external
return queue.add(() => {
    if (isCanceled) {
      return Promise.reject(new CancelError())
    }
    job = request(options)
    if (options.timeout) {
      job = timeout(job, options.timeout)
    }
    return job
  })
})
github sanity-io / sanity / packages / @sanity / cli / src / util / updateNotifier.js View on Github external
async function notify() {
    if (!process.stdout.isTTY) {
      return
    }

    const result = await pTimeout(check, MAX_BLOCKING_TIME, printCachedResult)
    if (hasPrintedResult) {
      debug('Has already printed result through timeout check, skipping result notification')
      return
    }

    printResult(result)
  }
github open-voip-alliance / WebphoneLib / src / ua.ts View on Github external
protected disconnectPromise(options: any = {}): Promise {
    return pTimeout(super.disconnectPromise(), 1000, () => {
      log.debug('Fake-closing the the socket by ourselves.', this.constructor.name);
      (this as any).onClose({ code: 'fake', reason: 'Artificial timeout' });
    }).then(() => ({ overrideEvent: true }));
  }
}

p-timeout

Timeout a promise after a specified amount of time

MIT
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis