88
99import Foundation
1010
11- public final class ColdSignal < Value, ErrorType: Error > : ColdSignalType , InternalSignalType , SpecialSignalGenerator {
11+ public final class ColdSignal < T, E: Error > : ColdSignalType , InternalSignalType , SpecialSignalGenerator {
12+
13+ public typealias Value = T
14+ public typealias ErrorType = E
15+
1216 internal var observers = Bag < Observer < Value , ErrorType > > ( )
1317
1418 public var coldSignal : ColdSignal {
@@ -77,20 +81,6 @@ public final class ColdSignal<Value, ErrorType: Error>: ColdSignalType, Internal
7781 started = false
7882 }
7983
80- /// Adds an observer to the ColdSignal which observes any future events from the
81- /// ColdSignal. If the Signal has already terminated, the observer will immediately
82- /// receive an `Interrupted` event.
83- ///
84- /// Returns a Disposable which can be used to disconnect the observer. Disposing
85- /// of the Disposable will have no effect on the Signal itself.
86- @discardableResult
87- public func add( observer: Observer < Value , ErrorType > ) -> Disposable ? {
88- let token = self . observers. insert ( value: observer)
89- return ActionDisposable {
90- self . observers. removeValueForToken ( token: token)
91- }
92- }
93-
9484}
9585
9686extension ColdSignal : CustomDebugStringConvertible {
@@ -121,7 +111,9 @@ public protocol ColdSignalType: SignalType {
121111public extension ColdSignalType {
122112
123113 public var signal : Signal < Value , ErrorType > {
124- return self . identity
114+ return Signal { observer in
115+ self . coldSignal. add ( observer: observer)
116+ }
125117 }
126118
127119 /// Invokes the closure provided upon initialization, and passes in a newly
@@ -141,6 +133,20 @@ public extension ColdSignalType {
141133
142134public extension ColdSignalType {
143135
136+ /// Adds an observer to the ColdSignal which observes any future events from the
137+ /// ColdSignal. If the Signal has already terminated, the observer will immediately
138+ /// receive an `Interrupted` event.
139+ ///
140+ /// Returns a Disposable which can be used to disconnect the observer. Disposing
141+ /// of the Disposable will have no effect on the Signal itself.
142+ @discardableResult
143+ public func add( observer: Observer < Value , ErrorType > ) -> Disposable ? {
144+ let token = coldSignal. observers. insert ( value: observer)
145+ return ActionDisposable {
146+ self . coldSignal. observers. removeValueForToken ( token: token)
147+ }
148+ }
149+
144150 /// Creates a ColdSignal, adds exactly one observer, and then immediately
145151 /// invokes start on the ColdSignal.
146152 ///
0 commit comments