How to complete a Multi depending on the previously received items #1513
Unanswered
samodadela
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You can use:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm using an MQTT service which when sent a certain message will respond with multiple responses. Each response contains some 'paging' info - the total number of expected responses and the 'id' of the current response. The responses can come out of order; e.g. get 1/3, 3/3 and 2/3.
The condition to end the Multi is to have received 3 out of 3 responses.
The thread that receives the responses is calling
emitter.emit()
on each item. The responses are opaque to this thread - they are parsed only later inonItem().transform()
. If this thread knew this is the last response, it could just callemitter.emit()
and thenemitter.complete()
and complete the stream.The problem is I don't know how to complete a Multi outside this thread, within the pipeline.
At first I thought to pass the emitter into
transform()
- but that would mean I'd callcomplete()
before returning an item. Probably not a good idea.Then I though of returning a failure, but that would mean the last element would not be emitted.
Or maybe I could create a
LastElementException
which would contain the last element and then recover with it. Doesn't look very good, though.Here's some code, to illustrate the problem:
Please suggest how this can be achieved? I'm stuck.
Beta Was this translation helpful? Give feedback.
All reactions