Fork me on GitHub
#om
<
2018-07-11
>
andreasklein09:07:15

How can I wait for a remote mutation to finish in om-next and then trigger some action?

danielstockton09:07:39

You can trigger re-reads on the remote that return new data, and act based on that data.

danielstockton09:07:35

If you want it to be asynchronous, you probably have to implement some kind of polling system.

andreasklein09:07:42

@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.

danielstockton09:07:14

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.

danielstockton09:07:33

Otherwise, you could return a job-id instead of pdf-url and poll for when it's ready.

danielstockton09:07:37

(by default, the backend parser is serial and executes each mutation or read in order)

danielstockton09:07:07

There are ways to implement async parsers, but that's another topic

andreasklein09:07:10

In this case :pdf-url is read before the transaction (some-key/create-pdf) is finished?

danielstockton09:07:57

No, in the default case, it will be run after (some-key/create-pdf) is finished.

danielstockton09:07:31

(someone please correct me if i'm horribly wrong)

andreasklein09:07:45

Hmm. That is sadly not the behaviour I see in my code

danielstockton09:07:06

Perhaps it depends on the implementation of create-pdf

andreasklein09:07:39

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

danielstockton09:07:20

Whether the :pdf-url key is read on the client depends on the client side parser

danielstockton09:07:26

You should also make sure that key triggers a remote read

danielstockton09:07:51

Do you receive the :pdf-url read in the remote query and return :pdf-url in the remote response?

andreasklein09:07:26

My client side read does currently not trigger a remote read

andreasklein09:07:29

I will try that

andreasklein09:07:13

Now the key is read after the first transaction finishes.

metal 4