Answer the question
In order to leave comments, you need to log in
Node.js event loop and async await?
There is the following code:
//добавляет путь файла в очередь string[];
enqueue(filePath: string): void {
this.queue.push(filePath);
if (!this.processing) {
this.processing = true;
this.ftp.connect().then(this.drain.bind(this));
}
}
// начинает извлекать пути из очереди, пока она не опустошится полностью
async drain(): Promise<void> {
if (this.queue.length) {
const filePath = this.queue.shift();
const fileStream = await this.ftp.get(filePath);
fileStream .on('data', chunk => this.entries.push(chunk.toString())).on('end', () => this.drain());
} else {
this.processing = false;
await this.ftp.disconnect();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question