# Is it possible to dispatch event asynchronously without waiting?

**URL:** <https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792>\
**Category:** Uncategorized\
**Created:** [March 14, 2023, 4:54pm UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792 "2023-03-14T16:54:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NirPisatto](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/nirpisatto/32/184_2.png) [@NirPisatto](https://discourse.nameko.io/u/NirPisatto)\
**Post date:** [March 14, 2023, 4:54pm UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792/1 "2023-03-14T16:54:55Z")

</div>

One of my event listening task (`event_handler`) is taking long time to processing. So is there any way to emit the event and let it work as async function without await? Thank !!

---

<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:** [March 15, 2023, 1:55pm UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792/2 "2023-03-15T13:55:53Z")

</div>

Can you explain in more detail what you’re trying to achieve?

The `event_handler` entrypoint is async by default – there is no client waiting for an answer. The only thing that waits for the method to finish is the `ACK` of the event message. It is implemented this way to make sure that, if the worker is interrupted somehow, the message is requeued for another handler to pick up.

---

<div class="post-metadata">

**Author:** ![NirPisatto](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/nirpisatto/32/184_2.png) [@NirPisatto](https://discourse.nameko.io/u/NirPisatto)\
**Post date:** [March 16, 2023, 4:08am UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792/3 "2023-03-16T04:08:25Z")

</div>

Hi mattbennett, Thank for your response.

My requerment is just want to dispatch the event handler without waiting, but in my case after dispatching the event\_handler the EventDispatcher is keep waiting until the event\_handler done process. Is ACK will respond back after the process done? or is there any configuration that I missed ?

I have attached some references to my case, as you can see there is a sleep for 20s in test event\_handler. When I dispatched this event, I expected it to take less than 20 seconds, but it almost never did. As I noted, the dispatcher will complete after the event\_handler done its operation.

**Event dispatching service**

 ![Screenshot from 2023-03-16 10-26-41](https://canada1.discourse-cdn.com/flex031/uploads/nameko/original/1X/f3cc8ad1589b1091d04006516b7d3ac9c3bb4028.png)

**Event listening service**

 ![Screenshot from 2023-03-16 10-26-15](https://canada1.discourse-cdn.com/flex031/uploads/nameko/original/1X/774df623525fb5f7fdaf897c01b418e7b41b1801.png)

**Reuslt**

 ![Screenshot from 2023-03-16 10-25-50](https://canada1.discourse-cdn.com/flex031/uploads/nameko/original/1X/6162165e289f29319d27468e67c4de55bb215ac9.png)

Addition  
I expected this event dispatcher to work, such as when I wrap event dispatcher in thread, since it worked when I use eventlet.spawn(event dispatcher).

---

<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:** [March 20, 2023, 9:25pm UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792/4 "2023-03-20T21:25:04Z")

</div>

You’re right to be confused. The “dispatch duration” printed should be milliseconds.

How are you running these services? It looks to me like you have not applied the [eventlet monkey patch](https://nameko.readthedocs.io/en/stable/key_concepts.html?highlight=monkey%20patch#concurrency).

---

<div class="post-metadata">

**Author:** ![NirPisatto](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/nirpisatto/32/184_2.png) [@NirPisatto](https://discourse.nameko.io/u/NirPisatto)\
**Post date:** [April 20, 2023, 4:39pm UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792/5 "2023-04-20T16:39:04Z")

</div>

Hi @mattbennett thank for your response.  
I have applied the [eventlet monkey patch](https://nameko.readthedocs.io/en/stable/key_concepts.html?highlight=monkey%20patch#concurrency) in my project.

And I found that, it because I run rpc and event handler service in ServiceRunner. It turn woking well asynchronously when I run service Individually. I got the same behavior when I tested with the nameko shell to run services. So mostly we don’t run rpc and event handler service in the same ServiceRunner?

---

<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:** [April 22, 2023, 7:47pm UTC](https://discourse.nameko.io/t/is-it-possible-to-dispatch-event-asynchronously-without-waiting/792/6 "2023-04-22T19:47:04Z")

</div>

I’m glad that applying the monkey patch solved your problem.

> [@NirPisatto](#):
>
> So mostly we don’t run rpc and event handler service in the same ServiceRunner?

Nameko can run multiple services inside the same runner without any problem. It’s often helpful to do this, for example when testing multiple services interoperating, but in production I recommend using a runner per service. That makes it easier to reason about things, and you generally get more capacity because (on a multi-core host) each service runner will potentially occupy its own core.
