Beta 7 with some repo names changed.

This commit is contained in:
Luis Fernando Molina committed 2020-11-15 13:05:19 +01:00
1 parent 0f7b40cca7
commit 963c19493a
3408 files changed
+462217 -15516

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
'use strict';
const pFinally = require('p-finally');
class TimeoutError extends Error {
constructor(message) {
super(message);
this.name = 'TimeoutError';
}
}
module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
if (typeof ms !== 'number' || ms < 0) {
throw new TypeError('Expected `ms` to be a positive number');
}
const timer = setTimeout(() => {
if (typeof fallback === 'function') {
resolve(fallback());
return;
}
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${ms} milliseconds`;
const err = fallback instanceof Error ? fallback : new TimeoutError(message);
reject(err);
}, ms);
pFinally(
promise.then(resolve, reject),
() => {
clearTimeout(timer);
}
);
});
module.exports.TimeoutError = TimeoutError;
+46
View File
@@ -0,0 +1,46 @@
{
"name": "p-timeout",
"version": "1.2.1",
"description": "Timeout a promise after a specified amount of time",
"license": "MIT",
"repository": "sindresorhus/p-timeout",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"promise",
"timeout",
"error",
"invalidate",
"async",
"await",
"promises",
"time",
"out",
"cancel",
"bluebird"
],
"dependencies": {
"p-finally": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"delay": "^2.0.0",
"xo": "*"
}
,"_resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-1.2.1.tgz"
,"_integrity": "sha1-XrOzU7f86Z8QGhA4iAuwVOu+o4Y="
,"_from": "p-timeout@^1.1.1"
}