fix(core): update
This commit is contained in:
parent
47b511f1f0
commit
6f1e32284d
@ -12,29 +12,25 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pnpm install -g pnpm
|
||||||
|
- pnpm install -g @shipzone/npmci
|
||||||
|
- npmci npm prepare
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --production --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command pnpm audit --audit-level=high --prod
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
@ -42,11 +38,10 @@ auditDevDependencies:
|
|||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
- npmci command pnpm audit --audit-level=high --dev
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
@ -57,7 +52,6 @@ auditDevDependencies:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -68,10 +62,9 @@ testStable:
|
|||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci npm build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
@ -97,10 +90,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -120,11 +112,9 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "# instrumented",
|
||||||
"type": "node",
|
"name": "Run instrumented terminal",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "lik",
|
"gitrepo": "lik",
|
||||||
"shortDescription": "light little helpers for node",
|
"description": "light little helpers for node",
|
||||||
"npmPackagename": "@pushrocks/lik",
|
"npmPackagename": "@pushrocks/lik",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)"
|
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -21,7 +21,6 @@ Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](htt
|
|||||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/lik)](https://lossless.cloud)
|
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/lik)](https://lossless.cloud)
|
||||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/lik)](https://lossless.cloud)
|
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/lik)](https://lossless.cloud)
|
||||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/lik)](https://lossless.cloud)
|
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/lik)](https://lossless.cloud)
|
||||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -48,7 +47,6 @@ We are always happy for code contributions. If you are not the code contributing
|
|||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
|
||||||
|
29
test/test.asyncexecutionstack.both.ts
Normal file
29
test/test.asyncexecutionstack.both.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
import * as lik from '../ts/index.js';
|
||||||
|
|
||||||
|
let testAsyncExecutionStack: lik.AsyncExecutionStack;
|
||||||
|
|
||||||
|
tap.test('should create a valid instance of AsyncExectionStack', async () => {
|
||||||
|
testAsyncExecutionStack = new lik.AsyncExecutionStack();
|
||||||
|
expect(testAsyncExecutionStack).toBeInstanceOf(lik.AsyncExecutionStack);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should run in parallel', async (toolsArg) => {
|
||||||
|
await testAsyncExecutionStack.getExclusiveExecutionSlot(async () => {
|
||||||
|
await toolsArg.delayFor(2000);
|
||||||
|
console.log('should run first');
|
||||||
|
}, 2500);
|
||||||
|
testAsyncExecutionStack.getNonExclusiveExecutionSlot(async () => {
|
||||||
|
await toolsArg.delayFor(2000);
|
||||||
|
console.log('should run third');
|
||||||
|
}, 2500);
|
||||||
|
testAsyncExecutionStack.getNonExclusiveExecutionSlot(async () => {
|
||||||
|
await toolsArg.delayFor(1000);
|
||||||
|
console.log('should run second');
|
||||||
|
}, 2500);
|
||||||
|
await testAsyncExecutionStack.getExclusiveExecutionSlot(async () => {
|
||||||
|
console.log('should run fourth');
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -14,14 +14,16 @@ tap.test('should find an entry', async () => {
|
|||||||
}>();
|
}>();
|
||||||
fastmap.addToMap('heythere', {
|
fastmap.addToMap('heythere', {
|
||||||
value1: 'heyho',
|
value1: 'heyho',
|
||||||
value2: 'heyho2'
|
value2: 'heyho2',
|
||||||
})
|
});
|
||||||
fastmap.addToMap('heythere2', {
|
fastmap.addToMap('heythere2', {
|
||||||
value1: 'heyho3',
|
value1: 'heyho3',
|
||||||
value2: 'heyho4'
|
value2: 'heyho4',
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await fastmap.find(async (itemArg)=> {return itemArg.value2 === 'heyho4'});
|
const result = await fastmap.find(async (itemArg) => {
|
||||||
|
return itemArg.value2 === 'heyho4';
|
||||||
|
});
|
||||||
expect(result.value1).toEqual('heyho3');
|
expect(result.value1).toEqual('heyho3');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/lik',
|
name: '@pushrocks/lik',
|
||||||
version: '6.0.1',
|
version: '6.0.2',
|
||||||
description: 'light little helpers for node'
|
description: 'light little helpers for node'
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export * from './lik.asyncexecutionstack.js'
|
export * from './lik.asyncexecutionstack.js';
|
||||||
export * from './lik.fastmap.js';
|
export * from './lik.fastmap.js';
|
||||||
export * from './lik.interestmap.js';
|
export * from './lik.interestmap.js';
|
||||||
export * from './lik.interestmap.interest.js';
|
export * from './lik.interestmap.interest.js';
|
||||||
|
@ -1,25 +1,82 @@
|
|||||||
import * as plugins from './lik.plugins.js'
|
import * as plugins from './lik.plugins.js';
|
||||||
|
|
||||||
|
interface IExecutionSlot<T> {
|
||||||
|
executionDeferred: plugins.smartpromise.Deferred<T>;
|
||||||
|
funcToExecute: () => Promise<T>;
|
||||||
|
timeout?: number;
|
||||||
|
mode: 'exclusive' | 'nonexclusive';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allows for avoiding race condition
|
* allows for avoiding race condition
|
||||||
*/
|
*/
|
||||||
export class AsyncExecutionStack {
|
export class AsyncExecutionStack {
|
||||||
public currentExecutions: Promise<any>[] = [];
|
private executionSlots: IExecutionSlot<any>[] = [];
|
||||||
public async getExclusiveExecutionSlot(funcArg: () => Promise<any>, timeoutArg: number) {
|
public async getExclusiveExecutionSlot<T = any>(funcArg: () => Promise<T>, timeoutArg?: number) {
|
||||||
const executionDeferred = plugins.smartpromise.defer();
|
const executionDeferred = plugins.smartpromise.defer<T>();
|
||||||
this.currentExecutions.push(executionDeferred.promise);
|
const executionSlot: IExecutionSlot<T> = {
|
||||||
for (const promiseArg of this.currentExecutions) {
|
funcToExecute: funcArg,
|
||||||
if (promiseArg !== executionDeferred.promise) {
|
executionDeferred,
|
||||||
await promiseArg;
|
timeout: timeoutArg,
|
||||||
} else {
|
mode: 'exclusive',
|
||||||
if (timeoutArg) {
|
};
|
||||||
await Promise.race([funcArg(),plugins.smartdelay.delayFor(timeoutArg)])
|
this.executionSlots.push(executionSlot);
|
||||||
} else {
|
this.processExecutionSlots();
|
||||||
await funcArg();
|
return executionDeferred.promise;
|
||||||
}
|
}
|
||||||
executionDeferred.resolve();
|
public async getNonExclusiveExecutionSlot<T = any>(
|
||||||
this.currentExecutions.shift();
|
funcArg: () => Promise<T>,
|
||||||
|
timeoutArg?: number
|
||||||
|
) {
|
||||||
|
const executionDeferred = plugins.smartpromise.defer<T>();
|
||||||
|
const executionSlot: IExecutionSlot<T> = {
|
||||||
|
funcToExecute: funcArg,
|
||||||
|
executionDeferred,
|
||||||
|
timeout: timeoutArg,
|
||||||
|
mode: 'nonexclusive',
|
||||||
|
};
|
||||||
|
this.executionSlots.push(executionSlot);
|
||||||
|
this.processExecutionSlots();
|
||||||
|
return executionDeferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private currentlyExecutingDeferred: plugins.smartpromise.Deferred<any>;
|
||||||
|
private async processExecutionSlots() {
|
||||||
|
if (this.currentlyExecutingDeferred) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.currentlyExecutingDeferred = plugins.smartpromise.defer();
|
||||||
|
let nonExclusiveRunningSlots: IExecutionSlot<any>[] = [];
|
||||||
|
const checkNonExclusiveRunningSlots = async (cleanArg = false) => {
|
||||||
|
if (nonExclusiveRunningSlots.length > 100 || cleanArg) {
|
||||||
|
await Promise.all(nonExclusiveRunningSlots.map(nonExclusiveRunningSlotArg => nonExclusiveRunningSlotArg.executionDeferred.promise));
|
||||||
|
nonExclusiveRunningSlots = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
while (this.executionSlots.length > 0) {
|
||||||
|
const nextExecutionSlot = this.executionSlots.shift();
|
||||||
|
const runNextExecution = async () => {
|
||||||
|
if (nextExecutionSlot.timeout) {
|
||||||
|
const result = await Promise.race([
|
||||||
|
nextExecutionSlot.funcToExecute(),
|
||||||
|
plugins.smartdelay.delayFor(nextExecutionSlot.timeout),
|
||||||
|
]);
|
||||||
|
nextExecutionSlot.executionDeferred.resolve(result);
|
||||||
|
} else {
|
||||||
|
nextExecutionSlot.executionDeferred.resolve(await nextExecutionSlot.funcToExecute());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (nextExecutionSlot.mode === 'exclusive') {
|
||||||
|
await checkNonExclusiveRunningSlots(true);
|
||||||
|
await runNextExecution();
|
||||||
|
} else {
|
||||||
|
nonExclusiveRunningSlots.push(nextExecutionSlot);
|
||||||
|
await checkNonExclusiveRunningSlots(false);
|
||||||
|
runNextExecution();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.currentlyExecutingDeferred.resolve();
|
||||||
|
this.currentlyExecutingDeferred = null;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -28,9 +28,8 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
|
|||||||
return this.comparisonFunc(this.originalInterest);
|
return this.comparisonFunc(this.originalInterest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private interestDeferred: plugins.smartpromise.Deferred<
|
private interestDeferred: plugins.smartpromise.Deferred<DTInterestFullfillment> =
|
||||||
DTInterestFullfillment
|
new plugins.smartpromise.Deferred();
|
||||||
> = new plugins.smartpromise.Deferred();
|
|
||||||
public interestFullfilled = this.interestDeferred.promise;
|
public interestFullfilled = this.interestDeferred.promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,6 @@ Subssequent interests will be mapped to the same interest
|
|||||||
which is then is only fullfilled once.
|
which is then is only fullfilled once.
|
||||||
=========== */
|
=========== */
|
||||||
|
|
||||||
|
|
||||||
import * as plugins from './lik.plugins.js';
|
import * as plugins from './lik.plugins.js';
|
||||||
import { ObjectMap } from './lik.objectmap.js';
|
import { ObjectMap } from './lik.objectmap.js';
|
||||||
import { Interest } from './lik.interestmap.interest.js';
|
import { Interest } from './lik.interestmap.interest.js';
|
||||||
|
@ -85,7 +85,7 @@ export class ObjectMap<T> {
|
|||||||
this.addMappedUnique(uniqueKey, objectArg);
|
this.addMappedUnique(uniqueKey, objectArg);
|
||||||
this.eventSubject.next({
|
this.eventSubject.next({
|
||||||
operation: 'add',
|
operation: 'add',
|
||||||
payload: objectArg
|
payload: objectArg,
|
||||||
});
|
});
|
||||||
return uniqueKey;
|
return uniqueKey;
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ export class ObjectMap<T> {
|
|||||||
const removedItem = this.fastMap.removeFromMap(keyToUse);
|
const removedItem = this.fastMap.removeFromMap(keyToUse);
|
||||||
this.eventSubject.next({
|
this.eventSubject.next({
|
||||||
operation: 'remove',
|
operation: 'remove',
|
||||||
payload: removedItem
|
payload: removedItem,
|
||||||
});
|
});
|
||||||
return removedItem;
|
return removedItem;
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ export class ObjectMap<T> {
|
|||||||
const removedObject = this.fastMap.removeFromMap(keyArg);
|
const removedObject = this.fastMap.removeFromMap(keyArg);
|
||||||
this.eventSubject.next({
|
this.eventSubject.next({
|
||||||
operation: 'remove',
|
operation: 'remove',
|
||||||
payload: removedObject
|
payload: removedObject,
|
||||||
});
|
});
|
||||||
return removedObject;
|
return removedObject;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user