@pushrocks/smartpromise
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -38,2 +38,3 @@ export interface IResolve<T> { | ||
export declare const timeoutWrap: <T = any>(promiseArg: Promise<T>, timeoutInMs: number) => Promise<T>; | ||
export declare const getFirstTrueOrFalse: (promisesArg: Promise<boolean>[]) => Promise<unknown>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.timeoutWrap = exports.map = exports.rejectedPromise = exports.resolvedPromise = exports.defer = exports.Deferred = void 0; | ||
exports.getFirstTrueOrFalse = exports.timeoutWrap = exports.map = exports.rejectedPromise = exports.resolvedPromise = exports.defer = exports.Deferred = void 0; | ||
class Deferred { | ||
@@ -73,2 +73,16 @@ constructor() { | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFVQSxNQUFhLFFBQVE7SUFnQm5CO1FBQ0UsSUFBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLE9BQU8sQ0FBSSxDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtZQUNoRCxJQUFJLENBQUMsT0FBTyxHQUFHLENBQUMsUUFBNEIsRUFBRSxFQUFFO2dCQUM5QyxJQUFJLENBQUMsTUFBTSxHQUFHLFdBQVcsQ0FBQztnQkFDMUIsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsR0FBRyxFQUFFLENBQUM7Z0JBQzVCLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztZQUNwQixDQUFDLENBQUM7WUFDRixJQUFJLENBQUMsTUFBTSxHQUFHLENBQUMsTUFBVyxFQUFFLEVBQUU7Z0JBQzVCLElBQUksQ0FBQyxNQUFNLEdBQUcsVUFBVSxDQUFDO2dCQUN6QixJQUFJ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xFQUFFO0lBQzVFLE1BQU0sWUFBWSxHQUFtQixFQUFFLENBQUM7SUFDeEMsTUFBTSxXQUFXLEdBQUcsRUFBRSxDQUFDO0lBQ3ZCLEtBQUssTUFBTSxJQUFJLElBQUksUUFBUSxFQUFFO1FBQzNCLE1BQU0sT0FBTyxHQUFpQixXQUFXLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDaEQsWUFBWSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUMzQixPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxFQUFFLEVBQUU7WUFDakIsV0FBVyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUN0QixDQUFDLENBQUMsQ0FBQztLQUNKO0lBQ0QsTUFBTSxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVksQ0FBQyxDQUFDO0lBQ2hDLE9BQU8sV0FBVyxDQUFDO0FBQ3JCLENBQUMsQ0FBQztBQUVXLFFBQUEsV0FBVyxHQUFHLENBQVUsVUFBc0IsRUFBRSxXQUFtQixFQUFFLEVBQUU7SUFDbEYsT0FBTyxJQUFJLE9BQU8sQ0FBSSxDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtRQUN4QyxVQUFVLENBQUMsR0FBRyxFQUFFO1lBQ2QsTUFBTSxDQUFDLElBQUksS0FBSyxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUM7UUFDL0IsQ0FBQyxFQUFFLFdBQVcsQ0FBQyxDQUFDO1FBQ2hCLFVBQVUsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLE1BQU0sQ0FBQyxDQUFDO0lBQ25DLENBQUMsQ0FBQyxDQUFDO0FBQ0wsQ0FBQyxDQUFDIn0= | ||
exports.getFirstTrueOrFalse = async (promisesArg) => { | ||
const done = exports.defer(); | ||
for (const promiseArg of promisesArg) { | ||
promiseArg.then((resultArg) => { | ||
if (resultArg === true) { | ||
done.resolve(true); | ||
} | ||
}); | ||
} | ||
Promise.all(promisesArg).then(() => { | ||
done.resolve(false); | ||
}); | ||
return done.promise; | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFVQSxNQUFhLFFBQVE7SUFnQm5CO1FBQ0UsSUFBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLE9BQU8sQ0FBSSxDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtZQUNoRCxJQUFJLENBQUMsT0FBTyxHQUFHLENBQUMsUUFBNEIsRUFBRSxFQUFFO2dCQUM5QyxJQUFJLENBQUMsTUFBTSxHQUFHLFdBQVcsQ0FBQztnQkFDMUIsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsR0FBRyxFQUFFLENBQUM7Z0JBQzVCLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztZQUNwQixDQUFDLENBQUM7WUFDRixJQUFJLENBQUMsTUFBTSxHQUFHLENBQUMsTUFBVyxFQUFFLEVBQUU7Z0JBQzVCLElBQUksQ0FBQyxNQUFNLEdBQUcsVUFBVSxDQUFDO2dCQUN6QixJQUFJLENBQUMsU0FBUyxHQUFHLElBQUksQ0FBQyxHQUFHLEVBQUUsQ0FBQztnQkFDNUIsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDO1lBQ2pCLENBQUMsQ0FBQztZQUNGLElBQUksQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFDO1lBQzVCLElBQUksQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDO1FBQzFCLENBQUMsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztJQXZCRCxJQUFXLFFBQVE7UUFDakIsSUFBSSxJQUFJLENBQUMsU0F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BQ2pDLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDdEIsQ0FBQyxDQUFDLENBQUM7SUFDSCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDdEIsQ0FBQyxDQUFDIn0= |
{ | ||
"name": "@pushrocks/smartpromise", | ||
"private": false, | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "simple promises and Deferred constructs", | ||
@@ -6,0 +6,0 @@ "main": "dist_ts/index.js", |
# @pushrocks/smartpromise | ||
simple promises and Deferred constructs | ||
## Availabililty and Links | ||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpromise) | ||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpromise) | ||
* [github.com (source mirror)](https://github.com/pushrocks/smartpromise) | ||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpromise/) | ||
- [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpromise) | ||
- [gitlab.com (source)](https://gitlab.com/pushrocks/smartpromise) | ||
- [github.com (source mirror)](https://github.com/pushrocks/smartpromise) | ||
- [docs (typedoc)](https://pushrocks.gitlab.io/smartpromise/) | ||
## Status for master | ||
[![build status](https://gitlab.com/pushrocks/smartpromise/badges/master/build.svg)](https://gitlab.com/pushrocks/smartpromise/commits/master) | ||
[![coverage report](https://gitlab.com/pushrocks/smartpromise/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartpromise/commits/master) | ||
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartpromise.svg)](https://www.npmjs.com/package/@pushrocks/smartpromise) | ||
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartpromise/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartpromise) | ||
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) | ||
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) | ||
Status Category | Status Badge | ||
-- | -- | ||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartpromise/badges/master/pipeline.svg)](https://lossless.cloud) | ||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartpromise/badges/master/coverage.svg)](https://lossless.cloud) | ||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartpromise)](https://lossless.cloud) | ||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartpromise)](https://lossless.cloud) | ||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) | ||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) | ||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) | ||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartpromise)](https://lossless.cloud) | ||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartpromise)](https://lossless.cloud) | ||
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) | ||
@@ -30,3 +34,3 @@ ## Usage | ||
```typescript | ||
import * as q from '@pushrocks/smartpromise' | ||
import * as q from '@pushrocks/smartpromise'; | ||
@@ -36,38 +40,38 @@ // Deferred | ||
let myAsyncFunction = (): Promise<string> => { | ||
let done = q.defer<string>() // returns your typical Deferred object | ||
let done = q.defer<string>(); // returns your typical Deferred object | ||
setTimeout(() => { | ||
done.resolve('hi') // will throw type error for other types than string as argument ;) | ||
},6000); | ||
done.resolve('hi'); // will throw type error for other types than string as argument ;) | ||
}, 6000); | ||
console.log(done.status) // logs "pending"; | ||
console.log(done.status); // logs "pending"; | ||
done.promise.then(() => { | ||
console.log(done.status) // logs "fullfilled" | ||
console.log(done.duration) // logs the milliseconds between instantiation and fullfillment | ||
}) | ||
console.log(done.status); // logs "fullfilled" | ||
console.log(done.duration); // logs the milliseconds between instantiation and fullfillment | ||
}); | ||
return done.promise | ||
} | ||
return done.promise; | ||
}; | ||
let myAsyncFunction2 = async () => { | ||
let aString = await myAsyncFunction() | ||
console.log(aString) // will log 'hi' to console | ||
} | ||
let aString = await myAsyncFunction(); | ||
console.log(aString); // will log 'hi' to console | ||
}; | ||
myAsyncFunction2(); | ||
// Resolved and Rejected promises | ||
// ------------------------------------------------ | ||
q.resolvedPromise(`I'll get logged to console soon`) | ||
.then(x => { | ||
console.log(x) | ||
}) | ||
q.resolvedPromise(`I'll get logged to console soon`).then((x) => { | ||
console.log(x); | ||
}); | ||
q.rejectedPromise(`what a lovely error message`) | ||
.then(() => { | ||
console.log('This never makes it to console') | ||
}/*, alternatively put a reject function here */) | ||
.catch(err => { | ||
console.log(err) | ||
}) | ||
.then( | ||
() => { | ||
console.log('This never makes it to console'); | ||
} /*, alternatively put a reject function here */ | ||
) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
@@ -78,16 +82,21 @@ // Promisify (typed) | ||
let myCallbackedFunction = (someString: string, someNumber: number, cb) => { | ||
cb(null, someString) | ||
} | ||
cb(null, someString); | ||
}; | ||
let myPromisedFunction = q.promisify(myCallbackFunction) | ||
myPromisedFunction('helloThere', 2).then(x => { | ||
console.log(x) // will log 'helloThere' to console | ||
}) | ||
let myPromisedFunction = q.promisify(myCallbackFunction); | ||
myPromisedFunction('helloThere', 2).then((x) => { | ||
console.log(x); // will log 'helloThere' to console | ||
}); | ||
``` | ||
## Contribution | ||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) | ||
For further information read the linked docs at the top of this readme. | ||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) | ||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | ||
| 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) |
@@ -95,1 +95,16 @@ export interface IResolve<T> { | ||
}; | ||
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => { | ||
const done = defer(); | ||
for (const promiseArg of promisesArg) { | ||
promiseArg.then((resultArg) => { | ||
if (resultArg === true) { | ||
done.resolve(true); | ||
} | ||
}); | ||
} | ||
Promise.all(promisesArg).then(() => { | ||
done.resolve(false); | ||
}); | ||
return done.promise; | ||
}; |
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
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
15801
238
100