I want to model the following scenario using ReactiveCocoa in swift.
class A{
let flagSignalProducer = A Signal Producer
someSignal.takeUntil(a signal that I can trigger manually which is created out of flagSignalProducer).subscribeNext{ (_) in
}
}
How can I create the Signal Producer and use the signal as takeUntil input signal and trigger the signal later manually. Am I doing it right way?
to make a signal that can emit manually you can use Signal<(), NoError>.pipe() to get a reference to the signal's "observer", which will allow you to manually send events on the signal.
let (flagSignal, flagObserver) = Signal<(), NoError>.pipe()
someSignal.takeUntil(flagSignal).observeNext { _ in
}
//somewhere else, trigger the signal manually with the Observer
flagObserver.sendNext(())
flagObserver.sendCompleted() //complete the signal and free memory
and if you need to convert your flagSignal to a SignalProducer for some reason, there is a SignalProducer constructor for that,
let flagSignalProducer = SignalProducer(signal: flagSignal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With