# Sending message as blocking function

**URL:** <https://forum.inductiveautomation.com/t/sending-message-as-blocking-function/65084>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 11, 2022, 7:57pm UTC](https://forum.inductiveautomation.com/t/sending-message-as-blocking-function/65084 "2022-10-11T19:57:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [October 11, 2022, 7:57pm UTC](https://forum.inductiveautomation.com/t/sending-message-as-blocking-function/65084/1 "2022-10-11T19:57:51Z")

</div>

Hi,

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?

Thanks

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 11, 2022, 8:29pm UTC](https://forum.inductiveautomation.com/t/sending-message-as-blocking-function/65084/2 "2022-10-11T20:29:34Z")

</div>

Look into using [system.util.sendRequest](https://docs.inductiveautomation.com/display/DOC81/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:

```auto
system.perspective.sendMessage("CallMessage")
self.props.text = "Waiting..."

```

And that same component has a configured listener of ResponseMessage:

```auto
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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 11, 2022, 10:18pm UTC](https://forum.inductiveautomation.com/t/sending-message-as-blocking-function/65084/3 "2022-10-11T22:18:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [October 12, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/sending-message-as-blocking-function/65084/4 "2022-10-12T15:55:46Z")

</div>

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.

Thanks  
Thanks
