SignalProducer
-
A SignalProducer creates Signals that can produce values of type
Valueand/or fail with errors of typeError. If no failure should be possible,NoErrorcan be specified forError.SignalProducers can be used to represent operations or tasks, like network requests, where each invocation of
start()will create a new underlying operation. This ensures that consumers will receive the results, versus a plain Signal, where the results might be sent before any observers are attached.Because of the behavior of
See morestart(), different Signals created from the producer may see a different version of Events. The Events may arrive in a different order between Signals, or the stream might be completely different!Declaration
Swift
public struct SignalProducer<Value, Error: Swift.Error>
-
Create a repeating timer of the given interval, with a reasonable default leeway, sending updates on the given scheduler.
Note
This timer will never complete naturally, so all invocations of
start()must be disposed to avoid leaks.Precondition
intervalmust be non-negative number.Note
If you plan to specify an
intervalvalue greater than 200,000 seconds, usetimer(interval:on:leeway:)instead and specify your ownleewayvalue to avoid potential overflow.Declaration
Swift
public func timer(interval: DispatchTimeInterval, on scheduler: DateScheduler) -> SignalProducer<Date, NoError>Parameters
intervalAn interval between invocations.
schedulerA scheduler to deliver events on.
Return Value
A producer that sends
NSDatevalues everyintervalseconds. -
Creates a repeating timer of the given interval, sending updates on the given scheduler.
Note
This timer will never complete naturally, so all invocations of
start()must be disposed to avoid leaks.Precondition
intervalmust be non-negative number.Precondition
leewaymust be non-negative number.Declaration
Swift
public func timer(interval: DispatchTimeInterval, on scheduler: DateScheduler, leeway: DispatchTimeInterval) -> SignalProducer<Date, NoError>Parameters
intervalAn interval between invocations.
schedulerA scheduler to deliver events on.
leewayInterval leeway. Apple’s “Power Efficiency Guide for Mac Apps” recommends a leeway of at least 10% of the timer interval.
Return Value
A producer that sends
NSDatevalues everyintervalseconds.
View on GitHub
Install in Dash
SignalProducer Reference