Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e43e2ea68 | |||
| 2a345f6514 | |||
| b536dc8ba2 | |||
| 6ca6cf6bc0 |
14
changelog.md
14
changelog.md
@@ -1,5 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-02-15 - 6.1.2 - fix(deps)
|
||||
bump @push.rocks/smarttime to ^4.2.3
|
||||
|
||||
- Updated @push.rocks/smarttime from ^4.1.1 to ^4.2.3
|
||||
- Non-breaking dependency version bump; increment patch version
|
||||
|
||||
## 2026-02-15 - 6.1.1 - fix(tests)
|
||||
improve buffered task tests: add chain, concurrency and queue behavior tests
|
||||
|
||||
- Replace tools.delayFor with @push.rocks/smartdelay for more deterministic timing in tests
|
||||
- Add tests for afterTask chaining, bufferMax concurrency, queued-run limits, and re-trigger behavior
|
||||
- Rename tasks to descriptive names and fix afterTask chaining order to avoid circular references
|
||||
- Change test runner invocation to export default tap.start() instead of calling tap.start() directly
|
||||
|
||||
## 2026-02-15 - 6.1.0 - feat(taskbuffer)
|
||||
add sliding-window rate limiting and result-sharing to TaskConstraintGroup and integrate with TaskManager
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/taskbuffer",
|
||||
"version": "6.1.0",
|
||||
"version": "6.1.2",
|
||||
"private": false,
|
||||
"description": "A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -40,7 +40,7 @@
|
||||
"@push.rocks/smartlog": "^3.1.11",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartrx": "^3.0.10",
|
||||
"@push.rocks/smarttime": "^4.1.1",
|
||||
"@push.rocks/smarttime": "^4.2.3",
|
||||
"@push.rocks/smartunique": "^3.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
52
pnpm-lock.yaml
generated
52
pnpm-lock.yaml
generated
@@ -27,8 +27,8 @@ importers:
|
||||
specifier: ^3.0.10
|
||||
version: 3.0.10
|
||||
'@push.rocks/smarttime':
|
||||
specifier: ^4.1.1
|
||||
version: 4.1.1
|
||||
specifier: ^4.2.3
|
||||
version: 4.2.3
|
||||
'@push.rocks/smartunique':
|
||||
specifier: ^3.0.9
|
||||
version: 3.0.9
|
||||
@@ -863,8 +863,8 @@ packages:
|
||||
'@push.rocks/smartstring@4.1.0':
|
||||
resolution: {integrity: sha512-Q4py/Nm3KTDhQ9EiC75yBtSTLR0KLMwhKM+8gGcutgKotZT6wJ3gncjmtD8LKFfNhb4lSaFMgPJgLrCHTOH6Iw==}
|
||||
|
||||
'@push.rocks/smarttime@4.1.1':
|
||||
resolution: {integrity: sha512-Ha/3J/G+zfTl4ahpZgF6oUOZnUjpLhrBja0OQ2cloFxF9sKT8I1COaSqIfBGDtoK2Nly4UD4aTJ3JcJNOg/kgA==}
|
||||
'@push.rocks/smarttime@4.2.3':
|
||||
resolution: {integrity: sha512-8gMg8RUkrCG4p9NcEUZV7V6KpL24+jAMK02g7qyhfA6giz/JJWD0+8w8xjSR+G7qe16KVQ2y3RbvAL9TxmO36g==}
|
||||
|
||||
'@push.rocks/smartunique@3.0.9':
|
||||
resolution: {integrity: sha512-q6DYQgT7/dqdWi9HusvtWCjdsFzLFXY9LTtaZV6IYNJt6teZOonoygxTdNt9XLn6niBSbLYrHSKvJNTRH/uK+g==}
|
||||
@@ -1795,8 +1795,8 @@ packages:
|
||||
typescript:
|
||||
optional: true
|
||||
|
||||
croner@9.1.0:
|
||||
resolution: {integrity: sha512-p9nwwR4qyT5W996vBZhdvBCnMhicY5ytZkR4D1Xj0wuTDEiMnjwR57Q3RXYY/s0EpX6Ay3vgIcfaR+ewGHsi+g==}
|
||||
croner@10.0.1:
|
||||
resolution: {integrity: sha512-ixNtAJndqh173VQ4KodSdJEI6nuioBWI0V1ITNKhZZsO0pEMoDxz539T4FTTbSZ/xIOSuDnzxLVRqBVSvPNE2g==}
|
||||
engines: {node: '>=18.0'}
|
||||
|
||||
cross-spawn@7.0.6:
|
||||
@@ -1814,8 +1814,8 @@ packages:
|
||||
date-fns@4.1.0:
|
||||
resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==}
|
||||
|
||||
dayjs@1.11.13:
|
||||
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
|
||||
dayjs@1.11.19:
|
||||
resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==}
|
||||
|
||||
debug@4.3.7:
|
||||
resolution: {integrity: sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==}
|
||||
@@ -2928,8 +2928,8 @@ packages:
|
||||
resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
pretty-ms@9.2.0:
|
||||
resolution: {integrity: sha512-4yf0QO/sllf/1zbZWYnvWw3NxCQwLXKzIj0G849LSufP15BXKM0rbD2Z3wVnkMfjdn/CB0Dpp444gYAACdsplg==}
|
||||
pretty-ms@9.3.0:
|
||||
resolution: {integrity: sha512-gjVS5hOP+M3wMm5nmNOucbIrqudzs9v/57bWRHQWLYklXqoXKrVfYW2W9+glfGsqtPgpiz5WwyEEB+ksXIx3gQ==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
progress@2.0.3:
|
||||
@@ -3584,7 +3584,7 @@ snapshots:
|
||||
'@push.rocks/smartrx': 3.0.10
|
||||
'@push.rocks/smartsitemap': 2.0.4
|
||||
'@push.rocks/smartstream': 3.2.5
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@push.rocks/taskbuffer': 3.5.0
|
||||
'@push.rocks/webrequest': 3.0.37
|
||||
'@push.rocks/webstore': 2.0.20
|
||||
@@ -4412,7 +4412,7 @@ snapshots:
|
||||
'@push.rocks/smartrequest': 5.0.1
|
||||
'@push.rocks/smarts3': 3.0.3
|
||||
'@push.rocks/smartshell': 3.3.0
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@types/ws': 8.18.1
|
||||
figures: 6.1.0
|
||||
ws: 8.19.0
|
||||
@@ -4777,7 +4777,7 @@ snapshots:
|
||||
'@push.rocks/smartmatch': 2.0.0
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smartrx': 3.0.10
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@types/minimatch': 5.1.2
|
||||
'@types/symbol-tree': 3.2.5
|
||||
symbol-tree: 3.2.4
|
||||
@@ -4899,7 +4899,7 @@ snapshots:
|
||||
'@push.rocks/smarterror': 2.0.1
|
||||
'@push.rocks/smarthash': 3.2.6
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
|
||||
'@push.rocks/smartchok@1.2.0':
|
||||
dependencies:
|
||||
@@ -4942,7 +4942,7 @@ snapshots:
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smartrx': 3.0.10
|
||||
'@push.rocks/smartstring': 4.1.0
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@push.rocks/smartunique': 3.0.9
|
||||
'@push.rocks/taskbuffer': 3.5.0
|
||||
'@tsclass/tsclass': 9.3.0
|
||||
@@ -5120,7 +5120,7 @@ snapshots:
|
||||
'@push.rocks/smartfile': 11.2.7
|
||||
'@push.rocks/smarthash': 3.2.6
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@push.rocks/webrequest': 4.0.1
|
||||
'@tsclass/tsclass': 9.3.0
|
||||
|
||||
@@ -5193,7 +5193,7 @@ snapshots:
|
||||
'@push.rocks/smartpath': 6.0.0
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smartrequest': 4.4.2
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@push.rocks/smartversion': 3.0.5
|
||||
package-json: 8.1.1
|
||||
transitivePeerDependencies:
|
||||
@@ -5362,7 +5362,7 @@ snapshots:
|
||||
'@push.rocks/smartlog': 3.1.11
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smartrx': 3.0.10
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
engine.io: 6.6.4
|
||||
socket.io: 4.8.1
|
||||
socket.io-client: 4.8.1
|
||||
@@ -5414,16 +5414,16 @@ snapshots:
|
||||
dependencies:
|
||||
'@push.rocks/isounique': 1.0.5
|
||||
|
||||
'@push.rocks/smarttime@4.1.1':
|
||||
'@push.rocks/smarttime@4.2.3':
|
||||
dependencies:
|
||||
'@push.rocks/lik': 6.2.2
|
||||
'@push.rocks/smartdelay': 3.0.5
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
croner: 9.1.0
|
||||
croner: 10.0.1
|
||||
date-fns: 4.1.0
|
||||
dayjs: 1.11.13
|
||||
dayjs: 1.11.19
|
||||
is-nan: 1.3.2
|
||||
pretty-ms: 9.2.0
|
||||
pretty-ms: 9.3.0
|
||||
|
||||
'@push.rocks/smartunique@3.0.9':
|
||||
dependencies:
|
||||
@@ -5459,7 +5459,7 @@ snapshots:
|
||||
'@push.rocks/smartlog': 3.1.11
|
||||
'@push.rocks/smartpromise': 4.2.3
|
||||
'@push.rocks/smartrx': 3.0.10
|
||||
'@push.rocks/smarttime': 4.1.1
|
||||
'@push.rocks/smarttime': 4.2.3
|
||||
'@push.rocks/smartunique': 3.0.9
|
||||
transitivePeerDependencies:
|
||||
- '@nuxt/kit'
|
||||
@@ -6474,7 +6474,7 @@ snapshots:
|
||||
optionalDependencies:
|
||||
typescript: 5.9.3
|
||||
|
||||
croner@9.1.0: {}
|
||||
croner@10.0.1: {}
|
||||
|
||||
cross-spawn@7.0.6:
|
||||
dependencies:
|
||||
@@ -6490,7 +6490,7 @@ snapshots:
|
||||
|
||||
date-fns@4.1.0: {}
|
||||
|
||||
dayjs@1.11.13: {}
|
||||
dayjs@1.11.19: {}
|
||||
|
||||
debug@4.3.7:
|
||||
dependencies:
|
||||
@@ -7866,7 +7866,7 @@ snapshots:
|
||||
dependencies:
|
||||
find-up: 4.1.0
|
||||
|
||||
pretty-ms@9.2.0:
|
||||
pretty-ms@9.3.0:
|
||||
dependencies:
|
||||
parse-ms: 4.0.0
|
||||
|
||||
|
||||
@@ -1,52 +1,151 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
import * as taskbuffer from '../ts/index.js';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
|
||||
let counter1 = 0;
|
||||
let counter2 = 0;
|
||||
let counter3 = 0;
|
||||
// Test 1: Basic buffered execution with afterTask chain
|
||||
tap.test('should run buffered tasks with afterTask chain', async () => {
|
||||
let counter1 = 0;
|
||||
let counter2 = 0;
|
||||
let counter3 = 0;
|
||||
|
||||
tap.test('should run buffered', async (tools) => {
|
||||
const task = new taskbuffer.Task({
|
||||
name: 'a buffered task',
|
||||
taskFunction: async () => {
|
||||
counter1++;
|
||||
await tools.delayFor(2000);
|
||||
console.log(`task 1 ran ${counter1} times`);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 1,
|
||||
afterTask: () => {
|
||||
return task2;
|
||||
},
|
||||
});
|
||||
const task2 = new taskbuffer.Task({
|
||||
name: 'a buffered task',
|
||||
taskFunction: async () => {
|
||||
counter2++;
|
||||
await tools.delayFor(2000);
|
||||
console.log(`task2 ran ${counter2} times`);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 1,
|
||||
afterTask: () => {
|
||||
return task3;
|
||||
},
|
||||
});
|
||||
const task3 = new taskbuffer.Task({
|
||||
name: 'a buffered task',
|
||||
name: 'buffered-chain-3',
|
||||
taskFunction: async () => {
|
||||
counter3++;
|
||||
await tools.delayFor(2000);
|
||||
console.log(`task3 ran ${counter3} times`);
|
||||
await smartdelay.delayFor(50);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 1,
|
||||
});
|
||||
while (counter1 < 10) {
|
||||
await tools.delayFor(5000);
|
||||
task.trigger();
|
||||
|
||||
const task2 = new taskbuffer.Task({
|
||||
name: 'buffered-chain-2',
|
||||
taskFunction: async () => {
|
||||
counter2++;
|
||||
await smartdelay.delayFor(50);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 1,
|
||||
afterTask: () => task3,
|
||||
});
|
||||
|
||||
const task1 = new taskbuffer.Task({
|
||||
name: 'buffered-chain-1',
|
||||
taskFunction: async () => {
|
||||
counter1++;
|
||||
await smartdelay.delayFor(50);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 1,
|
||||
afterTask: () => task2,
|
||||
});
|
||||
|
||||
// Trigger 3 times with enough spacing for the chain to complete
|
||||
for (let i = 0; i < 3; i++) {
|
||||
task1.trigger();
|
||||
await smartdelay.delayFor(250); // enough for chain of 3 x 50ms tasks
|
||||
}
|
||||
|
||||
// Wait for final chain to finish
|
||||
await smartdelay.delayFor(500);
|
||||
|
||||
// Each task in the chain should have run at least once
|
||||
expect(counter1).toBeGreaterThanOrEqual(1);
|
||||
expect(counter2).toBeGreaterThanOrEqual(1);
|
||||
expect(counter3).toBeGreaterThanOrEqual(1);
|
||||
|
||||
// afterTask chain means task2 count should match task1 (each trigger chains)
|
||||
expect(counter2).toEqual(counter1);
|
||||
expect(counter3).toEqual(counter1);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
// Test 2: bufferMax limits concurrent buffered executions
|
||||
tap.test('should respect bufferMax for concurrent buffered calls', async () => {
|
||||
let running = 0;
|
||||
let maxRunning = 0;
|
||||
let totalRuns = 0;
|
||||
|
||||
const task = new taskbuffer.Task({
|
||||
name: 'buffer-max-test',
|
||||
taskFunction: async () => {
|
||||
running++;
|
||||
maxRunning = Math.max(maxRunning, running);
|
||||
totalRuns++;
|
||||
await smartdelay.delayFor(100);
|
||||
running--;
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 2,
|
||||
});
|
||||
|
||||
// Fire many triggers rapidly — only bufferMax should run concurrently
|
||||
for (let i = 0; i < 10; i++) {
|
||||
task.trigger();
|
||||
}
|
||||
|
||||
// Wait for all buffered executions to complete
|
||||
await smartdelay.delayFor(1000);
|
||||
|
||||
expect(maxRunning).toBeLessThanOrEqual(2);
|
||||
expect(totalRuns).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
// Test 3: bufferMax limits how many runs are queued during execution
|
||||
tap.test('should limit queued runs to bufferMax during execution', async () => {
|
||||
let runCount = 0;
|
||||
|
||||
const task = new taskbuffer.Task({
|
||||
name: 'buffer-queue-test',
|
||||
taskFunction: async () => {
|
||||
runCount++;
|
||||
await smartdelay.delayFor(100);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 2,
|
||||
});
|
||||
|
||||
// Rapid-fire 5 triggers — bufferMax:2 means counter caps at 2
|
||||
// so only 2 runs will happen (the initial run + 1 buffered rerun)
|
||||
task.trigger();
|
||||
task.trigger();
|
||||
task.trigger();
|
||||
task.trigger();
|
||||
task.trigger();
|
||||
|
||||
await smartdelay.delayFor(500);
|
||||
|
||||
expect(runCount).toEqual(2);
|
||||
});
|
||||
|
||||
// Test 4: Triggers spaced after completion queue new runs
|
||||
tap.test('should re-trigger after previous buffered run completes', async () => {
|
||||
let runCount = 0;
|
||||
|
||||
const task = new taskbuffer.Task({
|
||||
name: 'retrigger-test',
|
||||
taskFunction: async () => {
|
||||
runCount++;
|
||||
await smartdelay.delayFor(50);
|
||||
},
|
||||
buffered: true,
|
||||
bufferMax: 1,
|
||||
});
|
||||
|
||||
// First trigger starts execution
|
||||
task.trigger();
|
||||
// Wait for it to complete
|
||||
await smartdelay.delayFor(100);
|
||||
|
||||
// Second trigger starts a new execution (task is now idle)
|
||||
task.trigger();
|
||||
await smartdelay.delayFor(100);
|
||||
|
||||
// Third trigger
|
||||
task.trigger();
|
||||
await smartdelay.delayFor(100);
|
||||
|
||||
expect(runCount).toEqual(3);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/taskbuffer',
|
||||
version: '6.1.0',
|
||||
version: '6.1.2',
|
||||
description: 'A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.'
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/taskbuffer',
|
||||
version: '6.1.0',
|
||||
version: '6.1.2',
|
||||
description: 'A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user