Compare commits

..

4 Commits

6 changed files with 3860 additions and 354 deletions

View File

@ -1,5 +1,15 @@
# Changelog
## 2025-01-19 - 4.2.0 - feat(cumulativedeferred)
Added subDefer method to CumulativeDeferred
- Introduced `subDefer` method in CumulativeDeferred class to allow creating and adding new Deferreds easily.
## 2025-01-07 - 4.1.0 - feat(core)
Add fromCallback utility function for promisifying Node.js-style callback functions
- Added fromCallback function to convert Node.js-style callbacks into Promises.
## 2024-06-23 - 4.0.4 - fix(ci)
Remove .gitlab-ci.yml and update dependencies and metadata
@ -7,8 +17,6 @@ Remove .gitlab-ci.yml and update dependencies and metadata
- Updated dependencies in package.json and npmextra.json
- Improved description and keywords for better package definition
## 2024-05-29 - 4.0.3 - Maintenance
Update project configuration and descriptions.
@ -85,4 +93,3 @@ Added polyfill and npmextra.json.
Updated continuous integration configuration.
- Update ci
```

View File

@ -1,7 +1,7 @@
{
"name": "@push.rocks/smartpromise",
"private": false,
"version": "4.0.4",
"version": "4.2.0",
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -21,11 +21,11 @@
},
"homepage": "https://code.foss.global/push.rocks/smartpromise",
"devDependencies": {
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tsbuild": "^2.2.0",
"@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.14.8"
"@push.rocks/tapbundle": "^5.5.5",
"@types/node": "^22.10.7"
},
"files": [
"ts/**/*",

4164
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartpromise',
version: '4.0.4',
version: '4.2.0',
description: 'A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.'
}

View File

@ -80,3 +80,22 @@ export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => {
});
return done.promise;
};
/**
* Converts a Node.js-style callback-based function into a Promise.
* @param fn The function that expects a callback.
* @returns A Promise that resolves with the result of the function or rejects with an error.
*/
export const fromCallback = <T>(
fn: (callback: (err: NodeJS.ErrnoException | null, result?: T) => void) => void
): Promise<T> => {
return new Promise((resolve, reject) => {
fn((err, result) => {
if (err) {
reject(err); // Reject the promise with the error
} else {
resolve(result as T); // Resolve the promise with the result
}
});
});
};

View File

@ -15,6 +15,12 @@ export class CumulativeDeferred {
}, 0);
}
public subDefer() {
const done = defer();
this.addPromise(done.promise);
return done;
}
public addPromise(promiseArg: Promise<any>) {
this.accumulatedPromises.push(promiseArg);
}