Merging effects on appear


I'm currently having problems merging effects onAppear. When the view appears I want to trigger an API request, and also subscribe to three socket channels (each of them represented by a publisher). I'm trying to achieve this behaviour using .merge:

    environment.getQuestions("Some_Id", "Some_Type", "filter")
        .receive(on: environment.queue)
        .cancellable(id: Cancellables()),
    environment.upvotePublisher("Some_Id", "Some_Type")
        .receive(on: environment.queue)
        .cancellable(id: Cancellables(), cancelInFlight: true),
    environment.updateQuestionPublisher("Some_Id", "Some_Type")
         .receive(on: environment.queue)
         .cancellable(id: Cancellables(), cancelInFlight: true),
     environment.deleteQuestionPublisher("Some_Id", "Some_Type")
         .receive(on: environment.queue)
         .cancellable(id: Cancellables(), cancelInFlight: true)

The problem that I have is that if I do this, the first effect (the api request) doesn't get triggered. I tried to replace .merge with .concatenate and it triggers the API and subscribes to the first publisher (as expected) but not for the las two (as the first publisher doesn't complete). Also if I fire the API effect alone, it works well.

I saw the examples on Github about subscribing to web sockets, and I think the .merge implementation should work just fine, but in reality it doesn't.

How are you handling this kind of scenarios? Are you doing something different?

Thank you!

Could it be that you're using same cancellable for all of them? Have you tried passing unique cancellables?

Hey eimantas, thank you for pointing that out. My problem was with the cancelInFlight: true flag. Basically that flag cancels any previous subscription with the same Cancellable ID, so I was merging the cancellation of every other publisher, so that I wasn't getting values. And as you mentioned, I'm using the same Cancellable ID for all the publishers.

Thank you for your help :slight_smile:

Terms of Service

Privacy Policy

Cookie Policy