fix(core): update

This commit is contained in:
2023-01-18 12:18:47 +01:00
parent 60a0fab9db
commit 24f82fe570
7 changed files with 4429 additions and 10371 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/lik',
version: '6.0.0',
version: '6.0.1',
description: 'light little helpers for node'
}

View File

@ -1,3 +1,4 @@
export * from './lik.asyncexecutionstack.js'
export * from './lik.fastmap.js';
export * from './lik.interestmap.js';
export * from './lik.interestmap.interest.js';

View File

@ -0,0 +1,25 @@
import * as plugins from './lik.plugins.js'
/**
* 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)])
} else {
await funcArg();
}
executionDeferred.resolve();
this.currentExecutions.shift();
}
}
};
}