SignalProducer
-
A SignalProducer creates Signals that can produce values of type
Value
and/or fail with errors of typeError
. If no failure should be possible,NoError
can 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
interval
must be non-negative number.Note
If you plan to specify an
interval
value greater than 200,000 seconds, usetimer(interval:on:leeway:)
instead and specify your ownleeway
value to avoid potential overflow.Declaration
Swift
public func timer(interval: DispatchTimeInterval, on scheduler: DateScheduler) -> SignalProducer<Date, NoError>
Parameters
interval
An interval between invocations.
scheduler
A scheduler to deliver events on.
Return Value
A producer that sends
NSDate
values everyinterval
seconds. -
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
interval
must be non-negative number.Precondition
leeway
must be non-negative number.Declaration
Swift
public func timer(interval: DispatchTimeInterval, on scheduler: DateScheduler, leeway: DispatchTimeInterval) -> SignalProducer<Date, NoError>
Parameters
interval
An interval between invocations.
scheduler
A scheduler to deliver events on.
leeway
Interval 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
NSDate
values everyinterval
seconds.