From 41ce7715327124ee88e003970c530c7cfebe7943 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 27 May 2016 15:25:46 +0200 Subject: [PATCH] extract extensions in a rolling fashion fixes #6947 --- src/vs/base/common/async.ts | 10 ++++++++++ src/vs/base/node/zip.ts | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/vs/base/common/async.ts b/src/vs/base/common/async.ts index 4e1030aa48d..35ca7d8f231 100644 --- a/src/vs/base/common/async.ts +++ b/src/vs/base/common/async.ts @@ -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(promiseTask: ITask>): TPromise { + return this.current = this.current.then(() => promiseTask()); + } +} + /** * A helper to delay execution of a task that is being requested often. * diff --git a/src/vs/base/node/zip.ts b/src/vs/base/node/zip.ts index b2403aea9c2..4c7e35ea056 100644 --- a/src/vs/base/node/zip.ts +++ b/src/vs/base/node/zip.ts @@ -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))); }); }); } -- GitLab