Reputation: 5446
A job queue for performing a copy operation using robocopy is established using the code below:
interface copyProcessReturn {
jobId: number,
code: number,
description: string,
params: string[],
source: string,
target: string,
jobsLeft: number
}
export default class CopyHandler {
private aQueue: AsyncQueue<copyProcess>;
constructor() {
let that = this;
this.aQueue = async.queue(function (cp: copyProcess) {
that.performCopy(cp);
that.copy_complete();
}, 1);
}
private copy_complete() {
// NOP
}
public addCopyProcess(cp: copyProcess): void {
this.aQueue.push(cp);
}
The aim is to enable the execution of one copy process at a time while maintaining concurrency in terms of adding additional copy processes to the queue.
This works fine for the first job and additional jobs get queued correctly. However, even though the copy_complete() callback is called correctly once a job is finished, its worker is not freed and additional jobs in the queue remain unprocessed.
I'd be very thankful for hints.
Upvotes: 0
Views: 200
Reputation: 5704
The function in async.queue has 2 arguments second being callback function that you need to call after that.copy_complete();
to let async library know that it has finished and it can run next fn in queue. Something like:
this.aQueue = async.queue(function (cp, next) {
that.performCopy(cp);
that.copy_complete();
next();
}, 1);
Upvotes: 1