Hi,
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
:
.merge(
environment.getQuestions("Some_Id", "Some_Type", "filter")
.receive(on: environment.queue)
.catchToEffect()
.map(Action.questionsResponse)
.cancellable(id: Cancellables()),
environment.upvotePublisher("Some_Id", "Some_Type")
.receive(on: environment.queue)
.catchToEffect()
.map(Action.updateUpvoteResponse)
.cancellable(id: Cancellables(), cancelInFlight: true),
environment.updateQuestionPublisher("Some_Id", "Some_Type")
.receive(on: environment.queue)
.catchToEffect()
.map(Action.updateQuestionResponse)
.cancellable(id: Cancellables(), cancelInFlight: true),
environment.deleteQuestionPublisher("Some_Id", "Some_Type")
.receive(on: environment.queue)
.catchToEffect()
.map(Action.updateDeleteQuestionResponse)
.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!