@pushrocks/smartpromise
Advanced tools
Comparing version 3.1.9 to 3.1.10
@@ -1,3 +0,19 @@ | ||
export * from './smartpromise.classes.cumulativedeferred.js'; | ||
export * from './smartpromise.classes.deferred.js'; | ||
export interface IResolve<T> { | ||
(value?: T | PromiseLike<T>): void; | ||
} | ||
export interface IReject { | ||
(reason?: any): void; | ||
} | ||
export declare type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected'; | ||
export declare class Deferred<T> { | ||
promise: Promise<T>; | ||
resolve: IResolve<T>; | ||
reject: IReject; | ||
status: TDeferredStatus; | ||
startedAt: number; | ||
stoppedAt: number; | ||
get duration(): number; | ||
constructor(); | ||
} | ||
export declare const defer: <T>() => Deferred<T>; | ||
/** | ||
@@ -24,1 +40,2 @@ * Creates a new resolved promise for the provided value. | ||
export declare const getFirstTrueOrFalse: (promisesArg: Promise<boolean>[]) => Promise<boolean>; | ||
export {}; |
@@ -1,8 +0,38 @@ | ||
import { defer } from './smartpromise.classes.deferred.js'; | ||
export * from './smartpromise.classes.cumulativedeferred.js'; | ||
export * from './smartpromise.classes.deferred.js'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFirstTrueOrFalse = exports.timeoutAndContinue = exports.timeoutWrap = exports.map = exports.rejectedPromise = exports.resolvedPromise = exports.defer = exports.Deferred = void 0; | ||
class Deferred { | ||
constructor() { | ||
this.promise = new Promise((resolve, reject) => { | ||
this.resolve = (valueArg) => { | ||
this.status = 'fulfilled'; | ||
this.stoppedAt = Date.now(); | ||
resolve(valueArg); | ||
}; | ||
this.reject = (reason) => { | ||
this.status = 'rejected'; | ||
this.stoppedAt = Date.now(); | ||
reject(reason); | ||
}; | ||
this.startedAt = Date.now(); | ||
this.status = 'pending'; | ||
}); | ||
} | ||
get duration() { | ||
if (this.stoppedAt) { | ||
return this.stoppedAt - this.startedAt; | ||
} | ||
else { | ||
return Date.now() - this.startedAt; | ||
} | ||
} | ||
} | ||
exports.Deferred = Deferred; | ||
exports.defer = () => { | ||
return new Deferred(); | ||
}; | ||
/** | ||
* Creates a new resolved promise for the provided value. | ||
*/ | ||
export const resolvedPromise = (value) => { | ||
exports.resolvedPromise = (value) => { | ||
return Promise.resolve(value); | ||
@@ -13,3 +43,3 @@ }; | ||
*/ | ||
export const rejectedPromise = (err) => { | ||
exports.rejectedPromise = (err) => { | ||
return Promise.reject(err); | ||
@@ -23,3 +53,3 @@ }; | ||
*/ | ||
export const map = async (inputArg, functionArg) => { | ||
exports.map = async (inputArg, functionArg) => { | ||
const promiseArray = []; | ||
@@ -37,3 +67,3 @@ const resultArray = []; | ||
}; | ||
export const timeoutWrap = async (promiseArg, timeoutInMsArg, rejectArg = true) => { | ||
exports.timeoutWrap = async (promiseArg, timeoutInMsArg, rejectArg = true) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -51,7 +81,7 @@ setTimeout(() => { | ||
}; | ||
export const timeoutAndContinue = async (promiseArg, timeoutInMsArg = 60000) => { | ||
return timeoutWrap(promiseArg, timeoutInMsArg, false); | ||
exports.timeoutAndContinue = async (promiseArg, timeoutInMsArg = 60000) => { | ||
return exports.timeoutWrap(promiseArg, timeoutInMsArg, false); | ||
}; | ||
export const getFirstTrueOrFalse = async (promisesArg) => { | ||
const done = defer(); | ||
exports.getFirstTrueOrFalse = async (promisesArg) => { | ||
const done = exports.defer(); | ||
for (const promiseArg of promisesArg) { | ||
@@ -69,2 +99,2 @@ promiseArg.then((resultArg) => { | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFFM0QsY0FBYyw4Q0FBOEMsQ0FBQztBQUM3RCxjQUFjLG9DQUFvQyxDQUFDO0FBR25EOztH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UFBQSxtQkFBbUIsR0FBRyxLQUFLLEVBQUUsV0FBK0IsRUFBRSxFQUFFO0lBQzNFLE1BQU0sSUFBSSxHQUFHLGFBQUssRUFBVyxDQUFDO0lBQzlCLEtBQUssTUFBTSxVQUFVLElBQUksV0FBVyxFQUFFO1FBQ3BDLFVBQVUsQ0FBQyxJQUFJLENBQUMsQ0FBQyxTQUFTLEVBQUUsRUFBRTtZQUM1QixJQUFJLFNBQVMsS0FBSyxJQUFJLEVBQUU7Z0JBQ3RCLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7YUFDcEI7UUFDSCxDQUFDLENBQUMsQ0FBQztLQUNKO0lBQ0QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLENBQUMsQ0FBQyxJQUFJLENBQUMsR0FBRyxFQUFFO1FBQ2pDLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDdEIsQ0FBQyxDQUFDLENBQUM7SUFDSCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDdEIsQ0FBQyxDQUFDIn0= |
@@ -12,3 +12,3 @@ { | ||
"gitrepo": "smartpromise", | ||
"description": "simple promises and Deferred constructs", | ||
"shortDescription": "simple promises and Deferred constructs", | ||
"npmPackagename": "@pushrocks/smartpromise", | ||
@@ -15,0 +15,0 @@ "license": "MIT" |
{ | ||
"name": "@pushrocks/smartpromise", | ||
"private": false, | ||
"version": "3.1.9", | ||
"version": "3.1.10", | ||
"description": "simple promises and Deferred constructs", | ||
@@ -10,4 +10,3 @@ "main": "dist_ts/index.js", | ||
"test": "(tstest test/ --web)", | ||
"build": "(tsbuild --web --allowimplicitany)", | ||
"buildDocs": "tsdoc" | ||
"build": "(tsbuild --web)" | ||
}, | ||
@@ -25,7 +24,8 @@ "repository": { | ||
"devDependencies": { | ||
"@gitzone/tsbuild": "^2.1.65", | ||
"@gitzone/tsrun": "^1.2.39", | ||
"@gitzone/tstest": "^1.0.74", | ||
"@pushrocks/tapbundle": "^5.0.4", | ||
"@types/node": "^18.15.11" | ||
"@gitzone/tsbuild": "^2.1.25", | ||
"@gitzone/tstest": "^1.0.54", | ||
"@pushrocks/tapbundle": "^3.2.14", | ||
"@types/node": "^15.6.1", | ||
"tslint": "^6.1.3", | ||
"tslint-config-prettier": "^1.18.0" | ||
}, | ||
@@ -46,4 +46,3 @@ "files": [ | ||
"last 1 chrome versions" | ||
], | ||
"type": "module" | ||
] | ||
} |
@@ -24,2 +24,3 @@ # @pushrocks/smartpromise | ||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartpromise)](https://lossless.cloud) | ||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud) | ||
@@ -95,4 +96,5 @@ ## Usage | ||
## Legal | ||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc) | ||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) | ||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | ||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) |
@@ -1,7 +0,49 @@ | ||
import { defer } from './smartpromise.classes.deferred.js'; | ||
export interface IResolve<T> { | ||
(value?: T | PromiseLike<T>): void; | ||
} | ||
export * from './smartpromise.classes.cumulativedeferred.js'; | ||
export * from './smartpromise.classes.deferred.js'; | ||
export interface IReject { | ||
(reason?: any): void; | ||
} | ||
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected'; | ||
export class Deferred<T> { | ||
public promise: Promise<T>; | ||
public resolve: IResolve<T>; | ||
public reject: IReject; | ||
public status: TDeferredStatus; | ||
public startedAt: number; | ||
public stoppedAt: number; | ||
public get duration(): number { | ||
if (this.stoppedAt) { | ||
return this.stoppedAt - this.startedAt; | ||
} else { | ||
return Date.now() - this.startedAt; | ||
} | ||
} | ||
constructor() { | ||
this.promise = new Promise<T>((resolve, reject) => { | ||
this.resolve = (valueArg: T | PromiseLike<T>) => { | ||
this.status = 'fulfilled'; | ||
this.stoppedAt = Date.now(); | ||
resolve(valueArg); | ||
}; | ||
this.reject = (reason: any) => { | ||
this.status = 'rejected'; | ||
this.stoppedAt = Date.now(); | ||
reject(reason); | ||
}; | ||
this.startedAt = Date.now(); | ||
this.status = 'pending'; | ||
}); | ||
} | ||
} | ||
export const defer = <T>() => { | ||
return new Deferred<T>(); | ||
}; | ||
/** | ||
@@ -45,7 +87,3 @@ * Creates a new resolved promise for the provided value. | ||
export const timeoutWrap = async <T = any>( | ||
promiseArg: Promise<T>, | ||
timeoutInMsArg: number, | ||
rejectArg = true | ||
) => { | ||
export const timeoutWrap = async <T = any>(promiseArg: Promise<T>, timeoutInMsArg: number, rejectArg = true) => { | ||
return new Promise<T>((resolve, reject) => { | ||
@@ -63,8 +101,5 @@ setTimeout(() => { | ||
export const timeoutAndContinue = async <T = any>( | ||
promiseArg: Promise<T>, | ||
timeoutInMsArg = 60000 | ||
) => { | ||
export const timeoutAndContinue = async <T = any>(promiseArg: Promise<T>, timeoutInMsArg = 60000) => { | ||
return timeoutWrap(promiseArg, timeoutInMsArg, false); | ||
}; | ||
} | ||
@@ -71,0 +106,0 @@ export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
99
16820
6
6
254
1
No