@mitm/common
Advanced tools
Comparing version 1.2.2 to 1.3.0
@@ -56,2 +56,9 @@ import { shareReplay } from 'rxjs/operators'; | ||
function wait(milliseconds = 0) { | ||
return new Promise(resolve => setTimeout(resolve, milliseconds)); | ||
} | ||
function waitThenReject(milliseconds = 0, error = new Error(`${waitThenReject.name} ${milliseconds}ms`)) { | ||
return new Promise((resolve, reject) => setTimeout(() => reject(error), milliseconds)); | ||
} | ||
/** | ||
@@ -165,2 +172,2 @@ * A RolesHierarchy holds a hierarchy of roles (surprised?) and provides utilities to query this hierarchy. | ||
export { RolesHierarchy, arrayPairwise, ensureNotNull, ethrow, evalThunk, filterOutNullArrayEntries, getStacktrace, normalizeToArray, shareReplayOne, throwThisShouldNeverHappenError, throwUnexpectedTypeError }; | ||
export { RolesHierarchy, arrayPairwise, ensureNotNull, ethrow, evalThunk, filterOutNullArrayEntries, getStacktrace, normalizeToArray, shareReplayOne, throwThisShouldNeverHappenError, throwUnexpectedTypeError, wait, waitThenReject }; |
@@ -64,2 +64,27 @@ (function (global, factory) { | ||
function wait(milliseconds) { | ||
if (milliseconds === void 0) { | ||
milliseconds = 0; | ||
} | ||
return new Promise(function (resolve) { | ||
return setTimeout(resolve, milliseconds); | ||
}); | ||
} | ||
function waitThenReject(milliseconds, error) { | ||
if (milliseconds === void 0) { | ||
milliseconds = 0; | ||
} | ||
if (error === void 0) { | ||
error = new Error(waitThenReject.name + " " + milliseconds + "ms"); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
return setTimeout(function () { | ||
return reject(error); | ||
}, milliseconds); | ||
}); | ||
} | ||
/** | ||
@@ -195,2 +220,4 @@ * A RolesHierarchy holds a hierarchy of roles (surprised?) and provides utilities to query this hierarchy. | ||
exports.throwUnexpectedTypeError = throwUnexpectedTypeError; | ||
exports.wait = wait; | ||
exports.waitThenReject = waitThenReject; | ||
@@ -197,0 +224,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "@mitm/common", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"main": "./common.umd.js", | ||
@@ -5,0 +5,0 @@ "module": "./common.esm.js", |
export declare type MaybePromise<T> = T | Promise<T>; | ||
export declare function wait(milliseconds?: number): Promise<void>; | ||
export declare function waitThenReject(milliseconds?: number, error?: Error): Promise<void>; |
18800
431