0001    //
0002    //  ConnectableObservable.swift
0003    //  Rx
0004    //
0005    //  Created by Krunoslav Zaher on 3/1/15.
0006    //  Copyright © 2015 Krunoslav Zaher. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    /**
0012     Represents an observable wrapper that can be connected and disconnected from its underlying observable sequence.
0013    */
0014    public class ConnectableObservable
ConnectableObservable.swift:59
    : ConnectableObservable<S.E> {
Observable+Binding.swift:29
        -> ConnectableObservable<S.E> {
Observable+Binding.swift:71
    public func publish() -> ConnectableObservable<E> {
Observable+Binding.swift:92
        -> ConnectableObservable<E> {
Observable+Binding.swift:107
		-> ConnectableObservable<E> {
<Element
ConnectableObservable.swift:15
    : Observable<Element>
> 0015 : Observable<Element> 0016 , ConnectableObservableType { 0017 0018 /** 0019 Connects the observable wrapper to its source. All subscribed observers will receive values from the underlying observable sequence as long as the connection is established. 0020 0021 - returns: Disposable used to disconnect the observable wrapper from its source, causing subscribed observer to stop receiving values from the underlying observable sequence. 0022 */ 0023 public func connect() -> Disposable { 0024 abstractMethod() 0025 } 0026 } 0027 0028 class Connection
ConnectableObservable.swift:60
    typealias ConnectionType = Connection<S>
ConnectableObservable.swift:83
            let connection = Connection(parent: self, subscription: disposable)
<S
ConnectableObservable.swift:31
    private weak var _parent: ConnectableObservableAdapter<S>?
ConnectableObservable.swift:34
    init(parent: ConnectableObservableAdapter<S>, subscription: Disposable) {
: SubjectType> : Disposable { 0029 0030 // state 0031 private weak var _parent
ConnectableObservable.swift:35
        _parent = parent
ConnectableObservable.swift:40
        guard let parent = _parent else { return }
ConnectableObservable.swift:48
            if _parent?._connection === self {
ConnectableObservable.swift:51
            _parent = nil
: ConnectableObservableAdapter<S>? 0032 private var _subscription
ConnectableObservable.swift:36
        _subscription = subscription
ConnectableObservable.swift:43
            guard let oldSubscription = _subscription else {
ConnectableObservable.swift:47
            _subscription = nil
: Disposable? 0033 0034 init
ConnectableObservable.swift:83
            let connection = Connection(parent: self, subscription: disposable)
(parent: ConnectableObservableAdapter<S>, subscription: Disposable) { 0035 _parent = parent 0036 _subscription = subscription 0037 } 0038 0039 func dispose() { 0040 guard let parent = _parent else { return } 0041 0042 parent._lock.performLocked { 0043 guard let oldSubscription = _subscription else { 0044 return 0045 } 0046 0047 _subscription = nil 0048 if _parent?._connection === self { 0049 parent._connection = nil 0050 } 0051 _parent = nil 0052 0053 oldSubscription.dispose() 0054 } 0055 } 0056 } 0057 0058 class ConnectableObservableAdapter
ConnectableObservable.swift:31
    private weak var _parent: ConnectableObservableAdapter<S>?
ConnectableObservable.swift:34
    init(parent: ConnectableObservableAdapter<S>, subscription: Disposable) {
Multicast.swift:26
            let connectable = ConnectableObservableAdapter(source: _parent._source, subject: subject)
Observable+Binding.swift:30
        return ConnectableObservableAdapter(source: self.asObservable(), subject: subject)
<S
ConnectableObservable.swift:59
    : ConnectableObservable<S.E> {
ConnectableObservable.swift:60
    typealias ConnectionType = Connection<S>
ConnectableObservable.swift:62
    private let _subject: S
ConnectableObservable.swift:63
    private let _source: Observable<S.SubjectObserverType.E>
ConnectableObservable.swift:70
    init(source: Observable<S.SubjectObserverType.E>, subject: S) {
ConnectableObservable.swift:70
    init(source: Observable<S.SubjectObserverType.E>, subject: S) {
ConnectableObservable.swift:89
    override func subscribe<O : ObserverType where O.E == S.E>(observer: O) -> Disposable {
: SubjectType> 0059 : ConnectableObservable<S.E> { 0060 typealias ConnectionType
ConnectableObservable.swift:68
    private var _connection: ConnectionType?
= Connection<S> 0061 0062 private let _subject
ConnectableObservable.swift:72
        _subject = subject
ConnectableObservable.swift:82
            let disposable = _source.subscribe(_subject.asObserver())
ConnectableObservable.swift:90
        return _subject.subscribe(observer)
: S 0063 private let _source
ConnectableObservable.swift:71
        _source = source
ConnectableObservable.swift:82
            let disposable = _source.subscribe(_subject.asObserver())
: Observable<S.SubjectObserverType.E> 0064 0065 private let _lock
ConnectableObservable.swift:42
        parent._lock.performLocked {
ConnectableObservable.swift:77
        return _lock.calculateLocked {
= NSRecursiveLock() 0066 0067 // state 0068 private var _connection
ConnectableObservable.swift:48
            if _parent?._connection === self {
ConnectableObservable.swift:49
                parent._connection = nil
ConnectableObservable.swift:73
        _connection = nil
ConnectableObservable.swift:78
            if let connection = _connection {
ConnectableObservable.swift:84
            _connection = connection
: ConnectionType? 0069 0070 init
Multicast.swift:26
            let connectable = ConnectableObservableAdapter(source: _parent._source, subject: subject)
Observable+Binding.swift:30
        return ConnectableObservableAdapter(source: self.asObservable(), subject: subject)
(source: Observable<S.SubjectObserverType.E>, subject: S) { 0071 _source = source 0072 _subject = subject 0073 _connection = nil 0074 } 0075 0076 override func connect
Multicast.swift:31
            let connection = connectable.connect()
() -> Disposable { 0077 return _lock.calculateLocked { 0078 if let connection = _connection { 0079 return connection 0080 } 0081 0082 let disposable = _source.subscribe(_subject.asObserver()) 0083 let connection = Connection(parent: self, subscription: disposable) 0084 _connection = connection 0085 return connection 0086 } 0087 } 0088 0089 override func subscribe<O : ObserverType where O.E == S.E>(observer: O) -> Disposable { 0090 return _subject.subscribe(observer) 0091 } 0092 }