Compare commits
No commits in common. "master" and "v6.2.1" have entirely different histories.
@ -1,12 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 2025-04-25 - 6.2.2 - fix(docs)
|
|
||||||
Update @push.rocks/tapbundle dependency and refine AsyncExecutionStack documentation examples
|
|
||||||
|
|
||||||
- Bump @push.rocks/tapbundle from ^5.0.8 to ^5.5.6 in package.json
|
|
||||||
- Improve README documentation for AsyncExecutionStack with clearer examples for exclusive and non-exclusive task execution
|
|
||||||
- Demonstrate usage of concurrency controls in AsyncExecutionStack
|
|
||||||
|
|
||||||
## 2025-04-25 - 6.2.1 - fix(AsyncExecutionStack tests)
|
## 2025-04-25 - 6.2.1 - fix(AsyncExecutionStack tests)
|
||||||
Refactor AsyncExecutionStack tests: update non-exclusive concurrency assertions and clean up test logic
|
Refactor AsyncExecutionStack tests: update non-exclusive concurrency assertions and clean up test logic
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/lik",
|
"name": "@push.rocks/lik",
|
||||||
"version": "6.2.2",
|
"version": "6.2.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Provides a collection of lightweight helpers and utilities for Node.js projects.",
|
"description": "Provides a collection of lightweight helpers and utilities for Node.js projects.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -26,7 +26,7 @@
|
|||||||
"@git.zone/tsbundle": "^2.0.15",
|
"@git.zone/tsbundle": "^2.0.15",
|
||||||
"@git.zone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@git.zone/tstest": "^1.0.90",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@push.rocks/tapbundle": "^5.5.6",
|
"@push.rocks/tapbundle": "^5.0.8",
|
||||||
"@types/node": "^22.13.9"
|
"@types/node": "^22.13.9"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@ -46,7 +46,7 @@ importers:
|
|||||||
specifier: ^1.0.90
|
specifier: ^1.0.90
|
||||||
version: 1.0.96(@aws-sdk/credential-providers@3.758.0)(socks@2.8.4)(typescript@5.7.3)
|
version: 1.0.96(@aws-sdk/credential-providers@3.758.0)(socks@2.8.4)(typescript@5.7.3)
|
||||||
'@push.rocks/tapbundle':
|
'@push.rocks/tapbundle':
|
||||||
specifier: ^5.5.6
|
specifier: ^5.0.8
|
||||||
version: 5.5.6(@aws-sdk/credential-providers@3.758.0)(socks@2.8.4)
|
version: 5.5.6(@aws-sdk/credential-providers@3.758.0)(socks@2.8.4)
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^22.13.9
|
specifier: ^22.13.9
|
||||||
|
51
readme.md
51
readme.md
@ -17,53 +17,22 @@ This will download `@push.rocks/lik` and add it to your project's `package.json`
|
|||||||
|
|
||||||
### AsyncExecutionStack
|
### AsyncExecutionStack
|
||||||
|
|
||||||
`AsyncExecutionStack` provides controlled execution of asynchronous tasks in two modes:
|
`AsyncExecutionStack` allows for managing asynchronous task execution with exclusive and non-exclusive slots, ensuring effective handling of resource-intensive operations.
|
||||||
|
|
||||||
- **Exclusive tasks**: run one at a time in insertion order, blocking all other tasks until complete.
|
|
||||||
- **Non-exclusive tasks**: run in parallel, up to an optional concurrency limit.
|
|
||||||
|
|
||||||
Create a stack:
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { AsyncExecutionStack } from '@push.rocks/lik';
|
import { AsyncExecutionStack } from '@push.rocks/lik';
|
||||||
|
|
||||||
const stack = new AsyncExecutionStack();
|
const myAsyncStack = new AsyncExecutionStack();
|
||||||
```
|
|
||||||
|
|
||||||
Exclusive tasks execute sequentially and block subsequent tasks (with an optional timeout):
|
// Exclusive execution ensures this task doesn't run in parallel with others
|
||||||
|
await myAsyncStack.getExclusiveExecutionSlot(async () => {
|
||||||
|
// some asynchronous operation
|
||||||
|
}, 2500);
|
||||||
|
|
||||||
```typescript
|
// Non-exclusive slots can run in parallel
|
||||||
await stack.getExclusiveExecutionSlot(
|
myAsyncStack.getNonExclusiveExecutionSlot(async () => {
|
||||||
async () => {
|
// another asynchronous operation
|
||||||
// exclusive work
|
}, 1500);
|
||||||
},
|
|
||||||
5000 // optional timeout in milliseconds
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
Non-exclusive tasks run in parallel up to the concurrency limit (default: unlimited). Each call returns a promise you can await:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const p1 = stack.getNonExclusiveExecutionSlot(async () => {
|
|
||||||
// work 1
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
const p2 = stack.getNonExclusiveExecutionSlot(async () => {
|
|
||||||
// work 2
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
await Promise.all([p1, p2]);
|
|
||||||
```
|
|
||||||
|
|
||||||
Control concurrency and inspect status:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// Set maximum concurrent non-exclusive tasks (minimum 1)
|
|
||||||
stack.setNonExclusiveMaxConcurrency(3);
|
|
||||||
|
|
||||||
console.log(stack.getNonExclusiveMaxConcurrency()); // 3
|
|
||||||
console.log(stack.getActiveNonExclusiveCount()); // currently running tasks
|
|
||||||
console.log(stack.getPendingNonExclusiveCount()); // tasks waiting for slots
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### FastMap
|
### FastMap
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/lik',
|
name: '@push.rocks/lik',
|
||||||
version: '6.2.2',
|
version: '6.2.1',
|
||||||
description: 'Provides a collection of lightweight helpers and utilities for Node.js projects.'
|
description: 'Provides a collection of lightweight helpers and utilities for Node.js projects.'
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user