Skip to content

Commit

Permalink
Add deferring initializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Apr 27, 2019
1 parent f9b6bad commit acdf6b2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ extension Signal {
self = Signal(evaluating: { result })
}

/// Defer the signal creation until an observer stars observing it.
/// A new signal is created for each observer.
///
/// - Parameter makeSignal: A closure to creates the signal.
public init<Other: SignalProtocol>(deferring makeSignal: @escaping () -> Other) where Other.Element == Element, Other.Error == Error {
self.init { observer in
return makeSignal().observe(with: observer)
}
}

/// Create a signal by evaluating a closure that returns result, propagating the success element as a
/// next event and completing immediately, or propagating the failure error as a failed event.
///
Expand Down

0 comments on commit acdf6b2

Please sign in to comment.