Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source observable sequence has completed and no further element will be bound. This may be something unexpected. #1431

Closed
adamsmaka opened this issue Oct 2, 2017 · 5 comments

Comments

@adamsmaka
Copy link

Just updated RxSwift from 3.4 to 4.0 beta.1 and started to seeing this warning in the console:

Source observable sequence has completed and no further element will be bound. This may be something unexpected.

What does it means? It wasn't a case before and I have no idea what causing it. :)

@kzaher
Copy link
Member

kzaher commented Oct 2, 2017

public struct Binder<Value>: ObserverType {
    public typealias E = Value
    
    private let _binding: (Event<Value>) -> ()

    /// Initializes `Binder`
    ///
    /// - parameter target: Target object.
    /// - parameter scheduler: Scheduler used to bind the events.
    /// - parameter binding: Binding logic.
    public init<Target: AnyObject>(_ target: Target, scheduler: ImmediateSchedulerType = MainScheduler(), binding: @escaping (Target, Value) -> ()) {
        weak var weakTarget = target

        _binding = { event in
            switch event {
            case .next(let element):
                _ = scheduler.schedule(element) { element in
                    if let target = weakTarget {
                        binding(target, element)
                    }
                    return Disposables.create()
                }
            case .error(let error):
                bindingError(error)
            case .completed:
                #if DEBUG
                    print("Source observable sequence has completed and no further element will be bound. This may be something unexpected.")
                #endif
                break
            }
        }
    }

    /// Binds next element to owner view as described in `binding`.
    public func on(_ event: Event<Value>) {
        _binding(event)
    }

    /// Erases type of observer.
    ///
    /// - returns: type erased observer.
    public func asObserver() -> AnyObserver<Value> {
        return AnyObserver(eventHandler: on)
    }
}

@kzaher kzaher closed this as completed Oct 2, 2017
@adamsmaka
Copy link
Author

adamsmaka commented Oct 2, 2017

This may be something unexpected.

In my case it's expected and I got a lot of warnings in my console now.

@kzaher kzaher reopened this Oct 2, 2017
@RamwiseMatt
Copy link

I'm doing the same thing (binding to an Observable that completes), and this warning doesn't really contribute much. Is the reason behind this warning that binding should only happen on hot observables?

@kzaher
Copy link
Member

kzaher commented Oct 7, 2017

I think that binding something finite is weird IMHO and is probably a bug.

However, I can remove this warning for the next release.

@kzaher
Copy link
Member

kzaher commented Oct 7, 2017

Removed.

@kzaher kzaher closed this as completed Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants