Skip to content

Commit 1aaab12

Browse files
authored
Merge pull request #86 from dolittle/fix-cancellation-instanceof
Fix cancellation instanceof
2 parents 4c77907 + a72ff3f commit 1aaab12

5 files changed

Lines changed: 45 additions & 5 deletions

File tree

Source/resilience/Cancellation.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ import { Observable, NEVER } from 'rxjs';
77
* Represents a possible cancellation.
88
*/
99
export class Cancellation extends Observable<void> {
10+
/**
11+
* Creates a new instance of the {@link Cancellation} class.
12+
* @param {Observable<void>} source - The source observable that indicates when a cancellation has occured.
13+
*/
14+
constructor(source: Observable<void>) {
15+
super(source.subscribe);
16+
}
1017

1118
/**
1219
* Default cancellation, which is never.
1320
*/
14-
static default: Cancellation = NEVER;
21+
static default: Cancellation = new Cancellation(NEVER);
1522
}

Source/resilience/CancellationSource.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Cancellation } from './Cancellation';
88
* Represents the source of a {@link Cancellation}.
99
*/
1010
export class CancellationSource {
11-
private _subject: Subject<void>;
11+
private readonly _subject: Subject<void>;
1212

1313
/**
1414
* Initializes a new instance of {@link CancellationSource}.
@@ -19,6 +19,7 @@ export class CancellationSource {
1919
for (const source of sources) {
2020
source.subscribe(this._subject);
2121
}
22+
this.cancellation = new Cancellation(this._subject);
2223
}
2324

2425
/**
@@ -31,9 +32,7 @@ export class CancellationSource {
3132
/**
3233
* Gets the cancellation subject.
3334
*/
34-
get cancellation(): Cancellation {
35-
return this._subject;
36-
}
35+
readonly cancellation: Cancellation;
3736

3837
/**
3938
* Get whether or not the {@link CancellationSource} is cancelled.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
import { describeThis } from '@dolittle/typescript.testing';
5+
import { Subject } from 'rxjs';
6+
import { Cancellation } from '../../index';
7+
8+
describeThis(__filename, () => {
9+
const result = new Cancellation(new Subject()) instanceof Cancellation;
10+
11+
it('should be', () => result.should.be.true);
12+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
import { describeThis } from '@dolittle/typescript.testing';
5+
import { Cancellation } from '../../index';
6+
7+
describeThis(__filename, () => {
8+
const result = Cancellation.default instanceof Cancellation;
9+
10+
it('should be', () => result.should.be.true);
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Dolittle. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
import { describeThis } from '@dolittle/typescript.testing';
5+
import { Cancellation, CancellationSource } from '../../index';
6+
7+
describeThis(__filename, () => {
8+
const result = new CancellationSource().cancellation instanceof Cancellation;
9+
10+
it('should be', () => result.should.be.true);
11+
});

0 commit comments

Comments
 (0)