Skip to content

Instantly share code, notes, and snippets.

@sergdort
Created June 3, 2017 16:47
Show Gist options
  • Save sergdort/66e21b1f4aaa65053700f1fb4cb08ea1 to your computer and use it in GitHub Desktop.
Save sergdort/66e21b1f4aaa65053700f1fb4cb08ea1 to your computer and use it in GitHub Desktop.
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