Skip to content

Hello, ask a question about Disposable, thanks #836

Open
@ijunfly

Description

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 !!!!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions