Skip to content

Commit

Permalink
CancellationToken#onCancellationRequested is a once-event by definiti…
Browse files Browse the repository at this point in the history
…on, helps with #81574
  • Loading branch information
jrieken committed Feb 12, 2020
1 parent 25b4479 commit 6ffa7d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/vs/base/common/cancellation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export interface CancellationToken {
readonly isCancellationRequested: boolean;

/**
* An event which fires when cancellation is requested.
* An event which fires when cancellation is requested. This event
* only ever fires `once` as cancellation can only happen once. Listeners
* that are registered after cancellation will be called (next event loop run),
* but also only once.
*
* @event
*/
Expand Down
5 changes: 2 additions & 3 deletions src/vs/base/node/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { mkdirp, rimraf } from 'vs/base/node/pfs';
import { open as _openZip, Entry, ZipFile } from 'yauzl';
import * as yazl from 'yazl';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Event } from 'vs/base/common/event';

export interface IExtractOptions {
overwrite?: boolean;
Expand Down Expand Up @@ -80,7 +79,7 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa

let istream: WriteStream;

Event.once(token.onCancellationRequested)(() => {
token.onCancellationRequested(() => {
if (istream) {
istream.destroy();
}
Expand All @@ -107,7 +106,7 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, tok
let last = createCancelablePromise<void>(() => Promise.resolve());
let extractedEntriesCount = 0;

Event.once(token.onCancellationRequested)(() => {
token.onCancellationRequested(() => {
last.cancel();
zipfile.close();
});
Expand Down
5 changes: 4 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ declare namespace monaco {
*/
readonly isCancellationRequested: boolean;
/**
* An event which fires when cancellation is requested.
* An event which fires when cancellation is requested. This event
* only ever fires `once` as cancellation can only happen once. Listeners
* that are registered after cancellation will be called (next event loop run),
* but also only once.
*
* @event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Emitter, Event } from 'vs/base/common/event';
import { Emitter } from 'vs/base/common/event';
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
Expand Down Expand Up @@ -153,7 +153,7 @@ export class RemoteFileSystemProvider extends Disposable implements

// Support cancellation
if (token) {
Event.once(token.onCancellationRequested)(() => {
token.onCancellationRequested(() => {

// Ensure to end the stream properly with an error
// to indicate the cancellation.
Expand Down

0 comments on commit 6ffa7d5

Please sign in to comment.