提交 41ce7715 编写于 作者: J Joao Moreno

extract extensions in a rolling fashion

fixes #6947
上级 b76da24d
......@@ -131,6 +131,16 @@ export class Throttler {
}
}
// TODO@Joao: can the previous throttler be replaced with this?
export class SimpleThrottler {
private current = TPromise.as(null);
queue<T>(promiseTask: ITask<TPromise<T>>): TPromise<T> {
return this.current = this.current.then(() => promiseTask());
}
}
/**
* A helper to delay execution of a task that is being requested often.
*
......
......@@ -7,7 +7,7 @@ import nls = require('vs/nls');
import * as path from 'path';
import { createWriteStream } from 'fs';
import { Readable } from 'stream';
import { nfcall, ninvoke, sequence } from 'vs/base/common/async';
import { nfcall, ninvoke, SimpleThrottler } from 'vs/base/common/async';
import { mkdirp, rimraf } from 'vs/base/node/pfs';
import { Promise, TPromise } from 'vs/base/common/winjs.base';
import { open as openZip, Entry, ZipFile } from 'yauzl';
......@@ -50,10 +50,11 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa
function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions): Promise {
return new Promise((c, e) => {
const promiseFactory: { (): Promise; }[] = [];
const throttler = new SimpleThrottler();
let last = TPromise.as(null);
zipfile.once('error', e);
zipfile.once('close', () => sequence(promiseFactory).then(c, e));
zipfile.once('close', () => last.then(c, e));
zipfile.on('entry', (entry: Entry) => {
if (!options.sourcePathRegex.test(entry.fileName)) {
return;
......@@ -63,7 +64,7 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions): Pr
const fileName = entry.fileName.replace(options.sourcePathRegex, '');
const mode = modeFromEntry(entry);
promiseFactory.push(() => stream.then(stream => extractEntry(stream, fileName, mode, targetPath, options)));
last = throttler.queue(() => stream.then(stream => extractEntry(stream, fileName, mode, targetPath, options)));
});
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册