UNPKG

731 BJavaScriptView Raw
1/******************************************************************************
2 *
3 * Copyright (c) 2018, the Perspective Authors.
4 *
5 * This file is part of the Perspective library, distributed under the terms of
6 * the Apache License 2.0. The full license can be found in the LICENSE file.
7 *
8 */
9
10export class CancelTask {
11 constructor(on_cancel, initial = false) {
12 this._on_cancel = on_cancel;
13 this._cancelled = false;
14 this.initial = initial;
15 }
16
17 cancel() {
18 if (!this._cancelled && this._on_cancel) {
19 this._on_cancel();
20 this._on_cancel = undefined;
21 }
22 this._cancelled = true;
23 }
24
25 get cancelled() {
26 return this._cancelled;
27 }
28}