0001 // 0002 // CombineLatest+CollectionType.swift 0003 // Rx 0004 // 0005 // Created by Krunoslav Zaher on 8/29/15. 0006 // Copyright © 2015 Krunoslav Zaher. All rights reserved. 0007 // 0008 0009 import Foundation 0010 0011 class CombineLatestCollectionTypeSink<C
CombineLatest+CollectionType.swift:121 let sink = CombineLatestCollectionTypeSink(parent: self, observer: observer): CollectionType, R
CombineLatest+CollectionType.swift:13 typealias Parent = CombineLatestCollectionType<C, R>CombineLatest+CollectionType.swift:14 typealias SourceElement = C.Generator.Element.E, O
CombineLatest+CollectionType.swift:13 typealias Parent = CombineLatestCollectionType<C, R>: ObserverType where C.Generator.Element : ObservableConvertibleType, O.E == R> 0012 : Sink<O> { 0013 typealias Parent
CombineLatest+CollectionType.swift:12 : Sink<O> {CombineLatest+CollectionType.swift:27 init(parent: Parent, observer: O) {= CombineLatestCollectionType<C, R> 0014 typealias SourceElement
CombineLatest+CollectionType.swift:16 let _parent: ParentCombineLatest+CollectionType.swift:27 init(parent: Parent, observer: O) {= C.Generator.Element.E 0015 0016 let _parent
CombineLatest+CollectionType.swift:22 var _values: [SourceElement?]CombineLatest+CollectionType.swift:29 _values = [SourceElement?](count: parent._count, repeatedValue: nil)CombineLatest+CollectionType.swift:41 func on(event: Event<SourceElement>, atIndex: Int) {: Parent 0017 0018 let _lock
CombineLatest+CollectionType.swift:28 _parent = parentCombineLatest+CollectionType.swift:51 if _numberOfValues < _parent._count {CombineLatest+CollectionType.swift:53 if numberOfOthersThatAreDone == self._parent._count - 1 {CombineLatest+CollectionType.swift:61 let result = try _parent._resultSelector(_values.map { $0! })CombineLatest+CollectionType.swift:80 if _numberOfDone == self._parent._count {CombineLatest+CollectionType.swift:93 for i in _parent._sources.startIndex ..< _parent._sources.endIndex {CombineLatest+CollectionType.swift:93 for i in _parent._sources.startIndex ..< _parent._sources.endIndex {CombineLatest+CollectionType.swift:95 let source = _parent._sources[i].asObservable()= NSRecursiveLock() 0019 0020 // state 0021 var _numberOfValues
CombineLatest+CollectionType.swift:42 _lock.lock(); defer { _lock.unlock() } // {CombineLatest+CollectionType.swift:42 _lock.lock(); defer { _lock.unlock() } // {= 0 0022 var _values
CombineLatest+CollectionType.swift:46 _numberOfValues += 1CombineLatest+CollectionType.swift:51 if _numberOfValues < _parent._count {: [SourceElement?] 0023 var _isDone
CombineLatest+CollectionType.swift:29 _values = [SourceElement?](count: parent._count, repeatedValue: nil)CombineLatest+CollectionType.swift:45 if _values[atIndex] == nil {CombineLatest+CollectionType.swift:49 _values[atIndex] = elementCombineLatest+CollectionType.swift:61 let result = try _parent._resultSelector(_values.map { $0! }): [Bool] 0024 var _numberOfDone
CombineLatest+CollectionType.swift:30 _isDone = [Bool](count: parent._count, repeatedValue: false)CombineLatest+CollectionType.swift:52 let numberOfOthersThatAreDone = self._numberOfDone - (_isDone[atIndex] ? 1 : 0)CombineLatest+CollectionType.swift:73 if _isDone[atIndex] {CombineLatest+CollectionType.swift:77 _isDone[atIndex] = true= 0 0025 var _subscriptions
CombineLatest+CollectionType.swift:52 let numberOfOthersThatAreDone = self._numberOfDone - (_isDone[atIndex] ? 1 : 0)CombineLatest+CollectionType.swift:78 _numberOfDone += 1CombineLatest+CollectionType.swift:80 if _numberOfDone == self._parent._count {: [SingleAssignmentDisposable] 0026 0027 init
CombineLatest+CollectionType.swift:31 _subscriptions = Array<SingleAssignmentDisposable>()CombineLatest+CollectionType.swift:32 _subscriptions.reserveCapacity(parent._count)CombineLatest+CollectionType.swift:35 _subscriptions.append(SingleAssignmentDisposable())CombineLatest+CollectionType.swift:85 _subscriptions[atIndex].dispose()CombineLatest+CollectionType.swift:96 _subscriptions[j].disposable = source.subscribe(AnyObserver { event inCombineLatest+CollectionType.swift:103 return CompositeDisposable(disposables: _subscriptions.map { $0 })(parent: Parent, observer: O) { 0028 _parent = parent 0029 _values = [SourceElement?](count: parent._count, repeatedValue: nil) 0030 _isDone = [Bool](count: parent._count, repeatedValue: false) 0031 _subscriptions = Array<SingleAssignmentDisposable>() 0032 _subscriptions.reserveCapacity(parent._count) 0033 0034 for _ in 0 ..< parent._count { 0035 _subscriptions.append(SingleAssignmentDisposable()) 0036 } 0037 0038 super.init(observer: observer) 0039 } 0040 0041 func on
CombineLatest+CollectionType.swift:121 let sink = CombineLatestCollectionTypeSink(parent: self, observer: observer)(event: Event<SourceElement>, atIndex: Int) { 0042 _lock.lock(); defer { _lock.unlock() } // { 0043 switch event { 0044 case .Next(let element): 0045 if _values[atIndex] == nil { 0046 _numberOfValues += 1 0047 } 0048 0049 _values[atIndex] = element 0050 0051 if _numberOfValues < _parent._count { 0052 let numberOfOthersThatAreDone = self._numberOfDone - (_isDone[atIndex] ? 1 : 0) 0053 if numberOfOthersThatAreDone == self._parent._count - 1 { 0054 forwardOn(.Completed) 0055 dispose() 0056 } 0057 return 0058 } 0059 0060 do { 0061 let result = try _parent._resultSelector(_values.map { $0! }) 0062 forwardOn(.Next(result)) 0063 } 0064 catch let error { 0065 forwardOn(.Error(error)) 0066 dispose() 0067 } 0068 0069 case .Error(let error): 0070 forwardOn(.Error(error)) 0071 dispose() 0072 case .Completed: 0073 if _isDone[atIndex] { 0074 return 0075 } 0076 0077 _isDone[atIndex] = true 0078 _numberOfDone += 1 0079 0080 if _numberOfDone == self._parent._count { 0081 forwardOn(.Completed) 0082 dispose() 0083 } 0084 else { 0085 _subscriptions[atIndex].dispose() 0086 } 0087 } 0088 // } 0089 } 0090 0091 func run
CombineLatest+CollectionType.swift:97 self.on(event, atIndex: index)() -> Disposable { 0092 var j = 0 0093 for i in _parent._sources.startIndex ..< _parent._sources.endIndex { 0094 let index = j 0095 let source = _parent._sources[i].asObservable() 0096 _subscriptions[j].disposable = source.subscribe(AnyObserver { event in 0097 self.on(event, atIndex: index) 0098 }) 0099 0100 j += 1 0101 } 0102 0103 return CompositeDisposable(disposables: _subscriptions.map { $0 }) 0104 } 0105 } 0106 0107 class CombineLatestCollectionType
CombineLatest+CollectionType.swift:122 sink.disposable = sink.run()<C
CombineLatest+CollectionType.swift:13 typealias Parent = CombineLatestCollectionType<C, R>Observable+Multiple.swift:25 return CombineLatestCollectionType(sources: self, resultSelector: resultSelector): CollectionType, R
CombineLatest+CollectionType.swift:108 typealias ResultSelector = [C.Generator.Element.E] throws -> RCombineLatest+CollectionType.swift:110 let _sources: CCombineLatest+CollectionType.swift:114 init(sources: C, resultSelector: ResultSelector) {where C.Generator.Element : ObservableConvertibleType> : Producer<R> { 0108 typealias ResultSelector
CombineLatest+CollectionType.swift:107 class CombineLatestCollectionType<C: CollectionType, R where C.Generator.Element : ObservableConvertibleType> : Producer<R> {CombineLatest+CollectionType.swift:108 typealias ResultSelector = [C.Generator.Element.E] throws -> RCombineLatest+CollectionType.swift:120 override func run<O : ObserverType where O.E == R>(observer: O) -> Disposable {= [C.Generator.Element.E] throws -> R 0109 0110 let _sources
CombineLatest+CollectionType.swift:111 let _resultSelector: ResultSelectorCombineLatest+CollectionType.swift:114 init(sources: C, resultSelector: ResultSelector) {: C 0111 let _resultSelector
CombineLatest+CollectionType.swift:93 for i in _parent._sources.startIndex ..< _parent._sources.endIndex {CombineLatest+CollectionType.swift:93 for i in _parent._sources.startIndex ..< _parent._sources.endIndex {CombineLatest+CollectionType.swift:95 let source = _parent._sources[i].asObservable()CombineLatest+CollectionType.swift:115 _sources = sourcesCombineLatest+CollectionType.swift:117 _count = Int(self._sources.count.toIntMax()): ResultSelector 0112 let _count
CombineLatest+CollectionType.swift:61 let result = try _parent._resultSelector(_values.map { $0! })CombineLatest+CollectionType.swift:116 _resultSelector = resultSelector: Int 0113 0114 init
CombineLatest+CollectionType.swift:29 _values = [SourceElement?](count: parent._count, repeatedValue: nil)CombineLatest+CollectionType.swift:30 _isDone = [Bool](count: parent._count, repeatedValue: false)CombineLatest+CollectionType.swift:32 _subscriptions.reserveCapacity(parent._count)CombineLatest+CollectionType.swift:34 for _ in 0 ..< parent._count {CombineLatest+CollectionType.swift:51 if _numberOfValues < _parent._count {CombineLatest+CollectionType.swift:53 if numberOfOthersThatAreDone == self._parent._count - 1 {CombineLatest+CollectionType.swift:80 if _numberOfDone == self._parent._count {CombineLatest+CollectionType.swift:117 _count = Int(self._sources.count.toIntMax())(sources: C, resultSelector: ResultSelector) { 0115 _sources = sources 0116 _resultSelector = resultSelector 0117 _count = Int(self._sources.count.toIntMax()) 0118 } 0119 0120 override func run<O : ObserverType where O.E == R>(observer: O) -> Disposable { 0121 let sink = CombineLatestCollectionTypeSink(parent: self, observer: observer) 0122 sink.disposable = sink.run() 0123 return sink 0124 } 0125 }
Observable+Multiple.swift:25 return CombineLatestCollectionType(sources: self, resultSelector: resultSelector)