ReactiveCocoa / ReactiveSwift

Streams of values over time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello, ask a question about Disposable, thanks

ijunfly opened this issue · comments

Hello everyone, after I created a SignalProducer, Disposable was weakly referenced, but after the SignalProducer was executed, Disposable was also printed, but why is the Disposable status incorrect?

class ViewController: UIViewController {
    weak var testDisposable: Disposable?
}

        self.testDisposable = SignalProducer(value: 3).delay(1, on: QueueScheduler.main).take(duringLifetimeOf: self).on(starting: {
            print("SignalProducer(value: 3) starting")
        }, started: {
            print("SignalProducer(value: 3) started")
        }, event: { (event) in
            print("SignalProducer(value: 3) event")
        }, failed: { (failed) in
            print("SignalProducer(value: 3) failed")
        }, completed: {
            print("SignalProducer(value: 3) completed")
        }, interrupted: {
            print("SignalProducer(value: 3) interrupted")
        }, terminated: {
            print("SignalProducer(value: 3) terminated")
        }, disposed: {
            print("SignalProducer(value: 3) disposed")
        }, value: { (x) in
            print("SignalProducer(value: 3) value: \(x)")
        }).start()
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            let a = self.testDisposable?.isDisposed == true
            print("self.testDisposable.isDisposed : \(a)")
        }

log

SignalProducer(value: 3) starting
SignalProducer(value: 3) started
SignalProducer(value: 3) event
SignalProducer(value: 3) value: 3
SignalProducer(value: 3) event
SignalProducer(value: 3) completed
SignalProducer(value: 3) terminated
SignalProducer(value: 3) disposed
self.testDisposable.isDisposed : false

谢谢各位大佬, Thank you !!!!

This can be used in ReactiveObjC, but it is different in ReactiveSwift.
Thanks again, Thanks again, Thanks again,