How can I wait for a remote mutation to finish in om-next and then trigger some action?
You can trigger re-reads on the remote that return new data, and act based on that data.
If you want it to be asynchronous, you probably have to implement some kind of polling system.
@danielstockton Thank you. Could you please elaborate a bit more on this concerning a more concrete example: I have a backend function which creates a pdf and would like to redirect to that pdf after it has been created. I try to use a remote mutation ’some-key/create-pdf but don’t see how to hook in after this mutation has finished.
It depends whether that pdf is generated in a background job or not. Something like
`[(some-key/create-pdf) :pdf-url]
could work, if you can afford to wait for the pdf to generate before returning the response.Otherwise, you could return a job-id
instead of pdf-url
and poll for when it's ready.
(by default, the backend parser is serial and executes each mutation or read in order)
There are ways to implement async parsers, but that's another topic
In this case :pdf-url is read before the transaction (some-key/create-pdf) is finished?
No, in the default case, it will be run after (some-key/create-pdf) is finished.
(someone please correct me if i'm horribly wrong)
Hmm. That is sadly not the behaviour I see in my code
Perhaps it depends on the implementation of create-pdf
I created a remote mutation that waits for 2 seconds and then finishes. In the meanwhile the :pdf-url key is read on the client
Whether the :pdf-url key is read on the client depends on the client side parser
You should also make sure that key triggers a remote read
Do you receive the :pdf-url read in the remote query and return :pdf-url
in the remote response?
My client side read does currently not trigger a remote read
I will try that
Aha!
Now the key is read after the first transaction finishes.