fix(core): update
This commit is contained in:
parent
47b511f1f0
commit
6f1e32284d
@ -12,29 +12,25 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
@ -42,11 +38,10 @@ auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- 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:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
@ -57,7 +52,6 @@ auditDevDependencies:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
@ -68,10 +62,9 @@ testStable:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
@ -97,10 +90,9 @@ codequality:
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -120,11 +112,9 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "# instrumented",
|
||||
"name": "Run instrumented terminal",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${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"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "lik",
|
||||
"shortDescription": "light little helpers for node",
|
||||
"description": "light little helpers for node",
|
||||
"npmPackagename": "@pushrocks/lik",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
@ -8,7 +8,8 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)"
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -53,4 +54,4 @@
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
}
|
@ -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 (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)
|
||||
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
|
||||
|
||||
@ -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.
|
||||
|
||||
> 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)
|
||||
|
||||
[![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,15 +14,17 @@ tap.test('should find an entry', async () => {
|
||||
}>();
|
||||
fastmap.addToMap('heythere', {
|
||||
value1: 'heyho',
|
||||
value2: 'heyho2'
|
||||
})
|
||||
value2: 'heyho2',
|
||||
});
|
||||
fastmap.addToMap('heythere2', {
|
||||
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');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
tap.start();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/lik',
|
||||
version: '6.0.1',
|
||||
version: '6.0.2',
|
||||
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.interestmap.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
|
||||
*/
|
||||
export class AsyncExecutionStack {
|
||||
public currentExecutions: Promise<any>[] = [];
|
||||
public async getExclusiveExecutionSlot(funcArg: () => Promise<any>, timeoutArg: number) {
|
||||
const executionDeferred = plugins.smartpromise.defer();
|
||||
this.currentExecutions.push(executionDeferred.promise);
|
||||
for (const promiseArg of this.currentExecutions) {
|
||||
if (promiseArg !== executionDeferred.promise) {
|
||||
await promiseArg;
|
||||
} else {
|
||||
if (timeoutArg) {
|
||||
await Promise.race([funcArg(),plugins.smartdelay.delayFor(timeoutArg)])
|
||||
private executionSlots: IExecutionSlot<any>[] = [];
|
||||
public async getExclusiveExecutionSlot<T = any>(funcArg: () => Promise<T>, timeoutArg?: number) {
|
||||
const executionDeferred = plugins.smartpromise.defer<T>();
|
||||
const executionSlot: IExecutionSlot<T> = {
|
||||
funcToExecute: funcArg,
|
||||
executionDeferred,
|
||||
timeout: timeoutArg,
|
||||
mode: 'exclusive',
|
||||
};
|
||||
this.executionSlots.push(executionSlot);
|
||||
this.processExecutionSlots();
|
||||
return executionDeferred.promise;
|
||||
}
|
||||
public async getNonExclusiveExecutionSlot<T = any>(
|
||||
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 {
|
||||
await funcArg();
|
||||
nextExecutionSlot.executionDeferred.resolve(await nextExecutionSlot.funcToExecute());
|
||||
}
|
||||
executionDeferred.resolve();
|
||||
this.currentExecutions.shift();
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
private interestDeferred: plugins.smartpromise.Deferred<
|
||||
DTInterestFullfillment
|
||||
> = new plugins.smartpromise.Deferred();
|
||||
private interestDeferred: plugins.smartpromise.Deferred<DTInterestFullfillment> =
|
||||
new plugins.smartpromise.Deferred();
|
||||
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.
|
||||
=========== */
|
||||
|
||||
|
||||
import * as plugins from './lik.plugins.js';
|
||||
import { ObjectMap } from './lik.objectmap.js';
|
||||
import { Interest } from './lik.interestmap.interest.js';
|
||||
|
@ -85,7 +85,7 @@ export class ObjectMap<T> {
|
||||
this.addMappedUnique(uniqueKey, objectArg);
|
||||
this.eventSubject.next({
|
||||
operation: 'add',
|
||||
payload: objectArg
|
||||
payload: objectArg,
|
||||
});
|
||||
return uniqueKey;
|
||||
}
|
||||
@ -140,7 +140,7 @@ export class ObjectMap<T> {
|
||||
/**
|
||||
* finds a specific element and then removes it
|
||||
*/
|
||||
public async findOneAndRemove(findFunction: IObjectmapFindFunction<T>): Promise<T> {
|
||||
public async findOneAndRemove(findFunction: IObjectmapFindFunction<T>): Promise<T> {
|
||||
const foundElement = await this.find(findFunction);
|
||||
if (foundElement) {
|
||||
this.remove(foundElement);
|
||||
@ -176,7 +176,7 @@ export class ObjectMap<T> {
|
||||
const removedItem = this.fastMap.removeFromMap(keyToUse);
|
||||
this.eventSubject.next({
|
||||
operation: 'remove',
|
||||
payload: removedItem
|
||||
payload: removedItem,
|
||||
});
|
||||
return removedItem;
|
||||
}
|
||||
@ -209,7 +209,7 @@ export class ObjectMap<T> {
|
||||
const removedObject = this.fastMap.removeFromMap(keyArg);
|
||||
this.eventSubject.next({
|
||||
operation: 'remove',
|
||||
payload: removedObject
|
||||
payload: removedObject,
|
||||
});
|
||||
return removedObject;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user