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

Crash in Observation+Combine l.36 #38

Closed
benrudhart opened this issue Mar 26, 2020 · 5 comments · Fixed by #39
Closed

Crash in Observation+Combine l.36 #38

benrudhart opened this issue Mar 26, 2020 · 5 comments · Fixed by #39
Labels
bug Something isn't working

Comments

@benrudhart
Copy link

Hi there,
I'm using a combine publisher like this

    private var myPublisher: NonFailingPublisher<Foo?> {
        Defaults
            .publisher(<FooName>, options: [.initial, .new])
            .compactMap { $0.newValue }
            .eraseToAnyPublisher()
    }

the output is assigned (through some mapping) to a text in a UILabel.

But when executed Defaults crashes in Observation+Combine l.36:

private func observationCallback(_ change: BaseChange) {
	_ = subscriber?.receive(change)
}

reason: Thread 1: Fatal error: Invalid state: Received value before receiving subscription

Maybe this issue is helpful (same error reason): CombineCommunity/RxCombine#6

One (hacky) way to fix this could be to dispatch _ = subscriber?.receive(change) to the next run loop via DispatchQueue.main.async { ... }

@sindresorhus
Copy link
Owner

// @fredyshox

@sindresorhus sindresorhus added the bug Something isn't working label Mar 26, 2020
@fredyshox
Copy link
Contributor

I can look into that.

@benrudhart
Copy link
Author

thank you!

@fredyshox
Copy link
Contributor

I fixed this bug in #39, sorry it took so long. It's weird, because I've been personally using this API in various projects, but never with .initial option, which caused issue here.

@benrudhart
Copy link
Author

Thank you for fixing this! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants