How to use the p-timeout.TimeoutError function in p-timeout

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 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 sindresorhus / p-queue / source / index.ts View on Github external
import EventEmitter = require('eventemitter3');
import {default as pTimeout, TimeoutError} from 'p-timeout';
import {Queue} from './queue';
import PriorityQueue from './priority-queue';
import {QueueAddOptions, DefaultAddOptions, Options} from './options';

type ResolveFunction = (value?: T | PromiseLike) => void;

type Task =
	| (() => PromiseLike)
	| (() => TaskResultType);

const empty = (): void => {};

const timeoutError = new TimeoutError();

/**
Promise queue with concurrency control.
*/
export default class PQueue = PriorityQueue, EnqueueOptionsType extends QueueAddOptions = DefaultAddOptions> extends EventEmitter<'active'> {
	private readonly _carryoverConcurrencyCount: boolean;

	private readonly _isIntervalIgnored: boolean;

	private _intervalCount = 0;

	private readonly _intervalCap: number;

	private readonly _interval: number;

	private _intervalEnd = 0;

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