Compare commits

...

4 Commits

Author SHA1 Message Date
1848006601 3.1.6 2021-05-31 13:02:23 +02:00
c761cc4460 fix(core): update 2021-05-31 13:02:22 +02:00
9f6d88e162 3.1.5 2021-04-23 18:04:09 +00:00
255d6415a5 fix(core): update 2021-04-23 18:04:08 +00:00
5 changed files with 16163 additions and 1473 deletions

17570
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "@pushrocks/smartpromise",
"private": false,
"version": "3.1.4",
"version": "3.1.6",
"description": "simple promises and Deferred constructs",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -19,12 +19,11 @@
"url": "https://gitlab.com/pushrocks/smartq/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartq#README",
"dependencies": {},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.8",
"@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"
},

View File

@ -86,7 +86,6 @@ myPromisedFunction('helloThere', 2).then((x) => {
});
```
## 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). :)

54
test/test.readme.node.ts Normal file
View File

@ -0,0 +1,54 @@
import * as smartpromise from '../ts';
// using Deferreds
// simple deferred;
const done = smartpromise.defer();
done.promise.then((stringArg) => {
console.log(stringArg);
});
done.resolve('hello') // whenever you are ready
// using deferreds in async functions to cater callback style apis
const myAsyncFunction = async (): Promise<string> => {
const done = smartpromise.defer<string>(); // returns your typical Deferred object
setTimeout(() => {
done.resolve('hi'); // will throw type error for other types than string as argument ;)
}, 6000);
console.log(done.status); // logs "pending";
await done.promise;
console.log(done.status); // logs "fullfilled"
console.log(done.duration); // outputs the duration in millisenconds
return done.promise;
};
let myAsyncFunction2 = async () => {
let aString = await myAsyncFunction();
console.log(aString); // will log 'hi' to console
};
myAsyncFunction2();
// Resolved and Rejected promises
// ------------------------------------------------
smartpromise.resolvedPromise(`I'll get logged to console soon`).then((x) => {
console.log(x);
});
smartpromise
.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);
});
import {tap, expect } from '@pushrocks/tapbundle';
tap.test('runs through', async () => {})
tap.start();

View File

@ -94,7 +94,7 @@ export const timeoutWrap = <T = any>(promiseArg: Promise<T>, timeoutInMs: number
};
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
const done = defer();
const done = defer<boolean>();
for (const promiseArg of promisesArg) {
promiseArg.then((resultArg) => {
if (resultArg === true) {