Request for New Feature: Enhancing Decorator Functionality with Queuing Mechanism
xziy opened this issue · 1 comments
xziy commented
Feature Request:
Overview:
The current decorator function, queued()
, aims to provide a queuing mechanism for asynchronous operations. However, it could be improved to offer enhanced functionality and broader applicability.
Code Sample:
interface QueueItem {
queue: Promise<void>;
}
function queued() {
return function (_target: any, _key: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) {
const operationQueue: QueueItem = { queue: Promise.resolve() };
const method = descriptor.value!;
descriptor.value = async function (...args: any[]) {
const operation = operationQueue.queue.then(async () => {
return await method.apply(this, args);
});
operationQueue.queue = operation.catch(() => {});
return operation;
};
return descriptor;
};
}
Additional Information:
- Use Case: The feature would benefit applications handling numerous asynchronous tasks, such as server-side processing or background jobs.
- Compatibility: Ensuring backward compatibility with existing code utilizing the
queued()
decorator will be crucial for seamless adoption.
Possible Implementation:
- Throttling: Implement a throttling mechanism within the queue to manage the rate of execution.
- Configuration Options: Introduce parameters or options within the decorator to customize queuing behavior.
Your contributions and insights to enhance this decorator are highly appreciated. Thank you for considering this request.
i found it here: https://gist.github.com/RomkeVdMeulen/f774324202d3fb8b710e7e2b1dcfdeb0#file-operationqueue-ts
vlio20 commented
Hi, can't you achive the same withthe ThrottleAsync decorator:
https://vlio20.github.io/utils-decorators/#throttleAsync