@peerbit/time
Advanced tools
Comparing version
@@ -26,7 +26,12 @@ export class TimeoutError extends Error { | ||
let stop = false; | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
}; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
// eslint-disable-next-line no-unmodified-loop-condition | ||
@@ -41,3 +46,8 @@ while (!stop && Number(new Date()) - startTime < timeout) { | ||
} | ||
throw createTimeoutError(options); | ||
if (aborted) { | ||
throw new AbortError(); | ||
} | ||
else { | ||
throw createTimeoutError(options); | ||
} | ||
}; | ||
@@ -50,7 +60,12 @@ export const waitForResolved = async (fn, options = { timeout: 10 * 1000, delayInterval: 50 }) => { | ||
let lastError; | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
}; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
// eslint-disable-next-line no-unmodified-loop-condition | ||
@@ -73,4 +88,7 @@ while (!stop && Number(new Date()) - startTime < timeout) { | ||
} | ||
if (aborted) { | ||
throw new AbortError(); | ||
} | ||
throw lastError || createTimeoutError(options); | ||
}; | ||
//# sourceMappingURL=wait.js.map |
120
package.json
{ | ||
"name": "@peerbit/time", | ||
"version": "2.0.7", | ||
"description": "Utility functions for time", | ||
"type": "module", | ||
"sideEffects": false, | ||
"types": "./dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"*", | ||
"dist/*", | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
], | ||
"src/*": [ | ||
"*", | ||
"dist/*", | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"!dist/test", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/src/index.d.ts", | ||
"import": "./dist/src/index.js" | ||
} | ||
}, | ||
"eslintConfig": { | ||
"extends": "peerbit", | ||
"parserOptions": { | ||
"project": true, | ||
"sourceType": "module" | ||
}, | ||
"ignorePatterns": [ | ||
"!.aegir.js", | ||
"test/ts-use", | ||
"*.d.ts" | ||
] | ||
}, | ||
"browser": { | ||
"./dist/src/hrtime.js": "./dist/src/hrtime.browser.js" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"clean": "aegir clean", | ||
"build": "aegir build --no-bundle", | ||
"test": "aegir test", | ||
"lint": "aegir lint" | ||
}, | ||
"author": "dao.xyz", | ||
"license": "MIT" | ||
"name": "@peerbit/time", | ||
"version": "2.0.8-5652381", | ||
"description": "Utility functions for time", | ||
"type": "module", | ||
"sideEffects": false, | ||
"types": "./dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"*", | ||
"dist/*", | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
], | ||
"src/*": [ | ||
"*", | ||
"dist/*", | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"!dist/test", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/src/index.d.ts", | ||
"import": "./dist/src/index.js" | ||
} | ||
}, | ||
"eslintConfig": { | ||
"extends": "peerbit", | ||
"parserOptions": { | ||
"project": true, | ||
"sourceType": "module" | ||
}, | ||
"ignorePatterns": [ | ||
"!.aegir.js", | ||
"test/ts-use", | ||
"*.d.ts" | ||
] | ||
}, | ||
"browser": { | ||
"./dist/src/hrtime.js": "./dist/src/hrtime.browser.js" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"clean": "aegir clean", | ||
"build": "aegir build --no-bundle", | ||
"test": "aegir test", | ||
"lint": "aegir lint" | ||
}, | ||
"author": "dao.xyz", | ||
"license": "MIT" | ||
} |
@@ -39,4 +39,6 @@ export class TimeoutError extends Error {} | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
@@ -46,2 +48,5 @@ }; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
@@ -58,3 +63,7 @@ // eslint-disable-next-line no-unmodified-loop-condition | ||
} | ||
throw createTimeoutError(options); | ||
if (aborted) { | ||
throw new AbortError(); | ||
} else { | ||
throw createTimeoutError(options); | ||
} | ||
}; | ||
@@ -78,4 +87,6 @@ | ||
let aborted = false; | ||
const handleAbort = () => { | ||
stop = true; | ||
aborted = true; | ||
options.signal?.removeEventListener("abort", handleAbort); | ||
@@ -85,2 +96,5 @@ }; | ||
options.signal?.addEventListener("abort", handleAbort); | ||
if (options?.signal?.aborted) { | ||
handleAbort(); | ||
} | ||
@@ -103,3 +117,7 @@ // eslint-disable-next-line no-unmodified-loop-condition | ||
if (aborted) { | ||
throw new AbortError(); | ||
} | ||
throw lastError || createTimeoutError(options); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21756
5.84%363
10.67%2
100%