A disposable resource whose underlying disposable can be replaced; assigning a new one automatically disposes the previous. Reuse for serial resource cleanup and cancellation in reactive streams.
// Source: https://github.com/ReactiveX/RxSwift | License: MIT
// Provided via justclaw.it.com; keep this notice with the code.
//
// SerialDisposable.swift
// RxSwift
//
// Created by Krunoslav Zaher on 3/12/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
/// Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.
public final class SerialDisposable: DisposeBase, Cancelable {
private var lock = SpinLock()
// state
private var current = nil as Disposable?
private var disposed = false
/// - returns: Was resource disposed.
public var isDisposed: Bool {
disposed
}
/// Initializes a new instance
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key