Sending message as blocking function


Sometimes I would like to send a Perspective message and await its return. For example the message does a databasee retrieve of info, and I want to be able to display "waiting..." while waiting for it.

I imagine that the message architecture makes that impossible, but does anyone have any ideas for simulating that?

I guess I should use a project script instead?


Look into using system.util.sendRequest instead. This will require use of the Gateway's message handlers I believe.

Alternatively, you could use a call-and-response sort of logic, where your origin point of the request does something like this:

self.props.text = "Waiting..."

And that same component has a configured listener of ResponseMessage:

self.props.text = payload["ImportantKey"]

But really, this seems like a bad use of sending messages, because they're meant to be ephemeral and not asynchronous, where it sounds like you have a defined step-by-step logic in mind.

Why doesn't the component sending the message in your use case just perform the logic it's waiting for the other component to return? If more than one component has a need for the logic, then it does seem like something that should be abstracted out into a project scripting library.

Some things simply need to be state machines implemented via a gateway timer event.


I ended up doing it all in the message handler - waiting message, query, then done. It needs to be done that way no matter what component is calling it from that same page. that may not be the most elegant solution but it is working, and I have full access to Perspective scope, as opposed to in a script.

I will keep that system.util.sendRequest in mind for next time, I haven't looked at that very much so it's not in the toolbox inventory in my head.