forked from dotnet/vscode-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Puszkiewicz
committed
Apr 10, 2018
1 parent
c65c4c5
commit 17c4140
Showing
8 changed files
with
85 additions
and
151 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Subscription } from "rxjs/Subscription"; | ||
import Disposable from "./Disposable"; | ||
|
||
export default class CompositeDisposable extends Disposable { | ||
private disposables = new Subscription(); | ||
|
||
constructor (...disposables: Disposable[]){ | ||
super(() => this.disposables.unsubscribe()); | ||
|
||
if (!disposables || disposables.length < 1) { | ||
throw new Error("disposables cannot be null or empty."); | ||
} | ||
|
||
for (const disposable of disposables) { | ||
if (disposable) { | ||
this.disposables.add(disposable.dispose); | ||
} | ||
else { | ||
throw new Error("null disposables are not supported"); | ||
} | ||
} | ||
} | ||
|
||
public add(disposable: Disposable | {(): void}) { | ||
if (!disposable) { | ||
throw new Error("disposable cannot be null"); | ||
} | ||
|
||
const actualDisposable = | ||
disposable.constructor.name === Disposable.name | ||
? <Disposable>disposable | ||
: new Disposable(<{(): void}>disposable); | ||
|
||
this.disposables.add(actualDisposable.dispose); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
export default class Disposable { | ||
private onDispose: {(): void}; | ||
|
||
constructor (onDispose: {(): void}){ | ||
if (!onDispose) { | ||
throw new Error("onDispose cannot be null or empty."); | ||
} | ||
|
||
this.onDispose = onDispose; | ||
} | ||
|
||
public dispose(): void { | ||
this.onDispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters