-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bulkhead #7
base: develop
Are you sure you want to change the base?
bulkhead #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice implementation. A few more checks are needed to ensure queue won't get blocked. Please review also the filename/directory name conventions. I think it should all be camelCase.
private readonly limit: number = Infinity, | ||
) { } | ||
|
||
public store(data: ExecutionMetaData<T>): this { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use standard queue method names, like push
and pop
instead of store
and next
@@ -0,0 +1,14 @@ | |||
import { Factory } from '../../interfaces/factory'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chances are low we will ever have another execution queue implementation than the current one. Therefore the factory here seems like an added complexity. I'd suggest rather to delete this file, and implement a static method static create<T>(limit: number): ExecutionQueue<T>
directly in the ExecutionQueue
class.
@@ -0,0 +1,57 @@ | |||
import { ExecutionQueue } from '../ExecutionQueue/ExecutionQueue'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bulkhead/Bulkhead.ts
doesn't sound nice. Maybe just bulkhead/index.ts
?
@@ -0,0 +1,18 @@ | |||
import { Factory } from '../../interfaces/factory'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for queue implementation, this factory is not of much use taking into account there won't be another bulkhead implementations. Now it looks like an added complexity. I'd suggest that we implement a static create method directly in the bulkhead class.
|
||
const result = method(...args); | ||
|
||
const afterExecution = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if async
is needed here.
private async execute(method: (...args: any[]) => Promise<T>, args: any[]) { | ||
this.inExecution += 1; | ||
|
||
const result = method(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided method
might throw an error, thus breaking our queue execution.
this.callNext(); | ||
}; | ||
|
||
result.then(afterExecution, afterExecution); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the method never resolves? It will stay forever in the queue and potentially might block the queue. I think we might need an additional option to setup a timeout for the execution. Could we use the @timeout
from current library? Either as a decorator, or directly as a method.
No description provided.