Skip to content

Commit

Permalink
fix bulkhead max wait time, update dependencies, bump v0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
cadgerfeast committed Dec 20, 2021
1 parent 2788582 commit 4ea3272
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mollitia",
"version": "0.0.7",
"version": "0.0.8",
"description": "JavaScript Resilience Library",
"main": "dist/mollitia.umd.js",
"module": "dist/mollitia.es5.js",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class EventEmitter {
public off (eventName: string, cb: EventCallback): void {
const listeners = this.listeners[eventName];
if (listeners) {
for (let i = listeners.length; i > 0; i--) {
for (let i = listeners.length - 1; i > 0; i--) {
if (listeners[i] === cb) {
listeners.splice(i, 1);
break;
Expand Down
17 changes: 11 additions & 6 deletions src/module/bulkhead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Module, ModuleOptions } from '.';
import { Circuit, CircuitFunction } from '../circuit';
import { EventEmitter } from '../helpers/event';

const MAX_TIMEOUT = 2147483647;

/**
* Properties that customizes the bulkhead behavior.
*/
Expand Down Expand Up @@ -123,12 +125,15 @@ export class Bulkhead extends Module {
this.concurrentBuffer.push(ref);
} else if (this.queueBuffer.length < this.queueSize) {
this.queueBuffer.push(ref);
const timeout = setTimeout(() => {
this.queueBuffer.splice(this.queueBuffer.indexOf(ref), 1);
resolveDisposable.dispose();
rejectDisposable.dispose();
reject(new BulkheadQueueWaitError());
}, this.maxQueueWait);
let timeout: number;
if (this.maxQueueWait <= MAX_TIMEOUT) {
timeout = <unknown>setTimeout(() => {
this.queueBuffer.splice(this.queueBuffer.indexOf(ref), 1);
resolveDisposable.dispose();
rejectDisposable.dispose();
reject(new BulkheadQueueWaitError());
}, this.maxQueueWait) as number;
}
const executeDisposable = ref.on('execute', () => {
executeDisposable.dispose();
clearTimeout(timeout);
Expand Down

0 comments on commit 4ea3272

Please sign in to comment.