# Event handling from within RPC?

**URL:** <https://discourse.nameko.io/t/event-handling-from-within-rpc/324>\
**Category:** Uncategorized\
**Created:** [August 17, 2018, 9:14pm UTC](https://discourse.nameko.io/t/event-handling-from-within-rpc/324 "2018-08-17T21:14:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HADDLETON\_Robert\_W\_B](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/haddleton_robert_w_b/32/20_2.png) [@HADDLETON\_Robert\_W\_B](https://discourse.nameko.io/u/HADDLETON_Robert_W_B)\
**Post date:** [August 17, 2018, 9:14pm UTC](https://discourse.nameko.io/t/event-handling-from-within-rpc/324/1 "2018-08-17T21:14:12Z")

</div>

Is there a way to have an RPC listen for an event inline?

I have an RPC that triggers an external action, and then it needs to wait until that action is complete before it can return. I can poll for the status of the external action, but the result of the external action also triggers an event in Nameko that I would like the RPC to be able to receive so it doesn’t have to poll.

I could have the RPC method block on a Redis key, and an event handler listen for the event and then set the key, but it adds complexity that seems unnecessary.

Is there an easier way?

Thanks,

Bob

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [August 19, 2018, 7:44pm UTC](https://discourse.nameko.io/t/event-handling-from-within-rpc/324/2 "2018-08-19T19:44:02Z")

</div>

Hi Bob,

I’d do exactly as you’ve described and use a redis lock.

There’s no out of the box way to do “inline” listening for events like this. You _could_ write a DependencyProvider that spawned a thread with an AMQP consumer which would block until the event arrived. It wouldn’t be a lot of code. But an event handler that just set the redis key would be even less.

Matt.
