Skip to content

QueryPublisher unsubscribes after one event #86

Open

Description

@Feuerwerk

Is there an existing issue?

Build info

  • ObjectBox version: 4.0.0

Steps to reproduce

let query: Query<Person> = ......
query.publisher
                    .replaceError(with: [])
                    /*.assign(to: \.persons, on: viewModel)*/
                    .sink(receiveValue: { persons in
                        viewModel.persons = persons
                    })
                    .store(in: &cancellables)

Expected behavior

I expected that viewModel.persons will update continuously when I add / change a record that will match my query.

Actual behavior

After the initial query result is consumed by the Subscriber, QueryPublisher will unsubscribe because various Subscriber implementations like sink(), assign(to:) or onReceive() of a SwiftUI view will return Subscriber.Demand.none which causes QueryPublisher to signal completion to the Subscriber and shut down.

Activity

  1. kemkriszt commented on Sep 25, 2024

    @kemkriszt

    I'm also curious of how to handle this, I ended up creating a custom subscriber that after every receive requests unlimited but it seems like an ugly hack to me

  2. greenrobot-team commented on Sep 30, 2024

    @greenrobot-team
    Member

    Thanks for reporting. The current publisher implementation indeed does send the finished event once it receives a none demand (so demand for 0) from the subscriber.

    I guess the underlying issue is that it uses Query.subscribe() behind the scenes which does not have a concept for demand. We should probably have a look at improving this, or maybe someone has an idea for an improvement?

    And so I think the current workaround is to use the subscribe APIs (like in the example) instead.

    (There is also an internal issue to improve SwiftUI support at objectbox/objectbox-swift#134.)

  3. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    on Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions