feat(core): Add concurrent processing support
This commit is contained in:
parent
e0a9030bcd
commit
7b3965ab2b
29
changelog.md
Normal file
29
changelog.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-01-04 - 1.1.0 - feat(core)
|
||||||
|
Add concurrent processing support
|
||||||
|
|
||||||
|
- Introduced ConcurrentProcessor class for handling asynchronous operations with a concurrency limit.
|
||||||
|
|
||||||
|
## 2024-05-29 - 1.0.8 - Documentation
|
||||||
|
Updated project description for clarity and accuracy.
|
||||||
|
|
||||||
|
- Enhanced documentation details in the project description.
|
||||||
|
|
||||||
|
## 2024-04-01 to 2024-04-27 - 1.0.5 to 1.0.7 - Maintenance and Configuration Updates
|
||||||
|
Multiple updates focusing on configuration and core functionality.
|
||||||
|
|
||||||
|
- Updated `tsconfig` for improved TypeScript setup.
|
||||||
|
- Refined `npmextra.json` to configure `githost`.
|
||||||
|
- Applied numerous core functionality enhancements and fixes.
|
||||||
|
|
||||||
|
## 2023-07-10 to 2023-08-02 - 1.0.3 to 1.0.4 - Organizational Changes and Fixes
|
||||||
|
Transition to new organizational structure and related updates.
|
||||||
|
|
||||||
|
- Implemented a new organizational scheme for the project.
|
||||||
|
- Applied essential fixes to core components ensuring stability.
|
||||||
|
|
||||||
|
## 2021-06-29 to 2021-06-30 - 1.0.1 to 1.0.2 - Core Fixes
|
||||||
|
Addressed core system updates and enhancements.
|
||||||
|
|
||||||
|
- Implemented bug fixes to enhance core functionality.
|
10
package.json
10
package.json
@ -13,12 +13,12 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^2.2.0",
|
||||||
"@git.zone/tsbundle": "^2.0.8",
|
"@git.zone/tsbundle": "^2.1.0",
|
||||||
"@git.zone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^1.3.3",
|
||||||
"@git.zone/tstest": "^1.0.77",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"@push.rocks/tapbundle": "^5.0.12",
|
"@push.rocks/tapbundle": "^5.5.4",
|
||||||
"@types/node": "^20.4.6"
|
"@types/node": "^22.10.5"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
9806
pnpm-lock.yaml
generated
9806
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartarray',
|
name: '@push.rocks/smartarray',
|
||||||
version: '1.0.8',
|
version: '1.1.0',
|
||||||
description: 'A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.'
|
description: 'A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.'
|
||||||
}
|
}
|
||||||
|
35
ts/classes.concurrentprocessor.ts
Normal file
35
ts/classes.concurrentprocessor.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
export class ConcurrentProcessor<T> {
|
||||||
|
private asyncFunction: (item: T) => Promise<void>;
|
||||||
|
private concurrencyLimit: number;
|
||||||
|
|
||||||
|
constructor(asyncFunction: (item: T) => Promise<void>, concurrencyLimit: number) {
|
||||||
|
this.asyncFunction = asyncFunction;
|
||||||
|
this.concurrencyLimit = concurrencyLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
async process(items: T[]): Promise<void> {
|
||||||
|
const queue: Array<Promise<void>> = [];
|
||||||
|
let totalProcessed = 0;
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
const promise = this.asyncFunction(item).then(() => {
|
||||||
|
totalProcessed++;
|
||||||
|
if (totalProcessed % 10000 === 0) {
|
||||||
|
console.log(`${totalProcessed} items processed.`);
|
||||||
|
}
|
||||||
|
// Remove the completed promise from the queue
|
||||||
|
queue.splice(queue.indexOf(promise), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
queue.push(promise);
|
||||||
|
|
||||||
|
// Wait if the number of promises exceeds the concurrency limit
|
||||||
|
if (queue.length >= this.concurrencyLimit) {
|
||||||
|
await Promise.race(queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the remaining promises to resolve
|
||||||
|
await Promise.all(queue);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
export * from './classes.concurrentprocessor.js';
|
||||||
|
|
||||||
export const map = async <T = any, R = any>(
|
export const map = async <T = any, R = any>(
|
||||||
arrayArg: T[],
|
arrayArg: T[],
|
||||||
mapFunction: (itemArg: T) => Promise<R>
|
mapFunction: (itemArg: T) => Promise<R>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user