Created
June 3, 2017 16:47
-
-
Save sergdort/66e21b1f4aaa65053700f1fb4cb08ea1 to your computer and use it in GitHub Desktop.
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
public final class AnonimousDisposable: Disposable { | |
private let _disposeHandler: () -> Void | |
public init(_ disposeClosure: @escaping () -> Void) { | |
_disposeHandler = disposeClosure | |
} | |
public func dispose() { | |
_disposeHandler() | |
} | |
} | |
public final class CompositeDisposable: Disposable { | |
private var isDisposed: Bool = false | |
private var disposables: [Disposable] = [] | |
public init() {} | |
public func add(disposable: Disposable) { | |
if isDisposed { | |
disposable.dispose() | |
return | |
} | |
disposables.append(disposable) | |
} | |
public func dispose() { | |
if isDisposed { return } | |
disposables.forEach { | |
$0.dispose() | |
} | |
isDisposed = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment