fix(core): update
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/lik',
|
||||
version: '6.0.0',
|
||||
version: '6.0.1',
|
||||
description: 'light little helpers for node'
|
||||
}
|
||||
|
@ -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';
|
||||
|
25
ts/lik.asyncexecutionstack.ts
Normal file
25
ts/lik.asyncexecutionstack.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user