Skip to content

Commit 6225d35

Browse files
authored
cancellable: Add combine() convenience method (#99)
1 parent 9e01166 commit 6225d35

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/cancellable.ts

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ export class Cancellable {
2929
return "Cancellable {}";
3030
}
3131

32+
combine(other: Cancellable): Cancellable {
33+
const cancel = new Cancellable();
34+
this.cancelled.connect(() => cancel.cancel());
35+
other.cancelled.connect(() => cancel.cancel());
36+
if (this.isCancelled) cancel.cancel();
37+
if (other.isCancelled) cancel.cancel();
38+
return cancel;
39+
}
40+
3241
public static withTimeout(ms): Cancellable {
3342
const cancel = new Cancellable();
3443
setTimeout(() => cancel.cancel(), ms).unref();

0 commit comments

Comments
 (0)