# GenServer blocking in async task

**URL:** <https://forum.elixirforum.com/t/genserver-blocking-in-async-task/32635>\
**Category:** Questions\
**Tags:** task, exunit, asynchronous, genserver\
**Created:** [June 25, 2020, 1:49pm UTC](https://forum.elixirforum.com/t/genserver-blocking-in-async-task/32635 "2020-06-25T13:49:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jtsummers](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtsummers/32/19607_2.png) [@jtsummers](https://forum.elixirforum.com/u/jtsummers)\
**Post date:** [June 25, 2020, 4:32pm UTC](https://forum.elixirforum.com/t/genserver-blocking-in-async-task/32635/2 "2020-06-25T16:32:28Z")

</div>

Because you’re spawning a task that then spawns the server you’re hitting a race condition. The named server doesn’t exist yet. Rather than using a timer (which either wastes time or cuts it too close and has a chance of failure), you can try [`GenServer.whereis`](https://hexdocs.pm/elixir/GenServer.html#whereis/1). If it returns `nil` then the named server hasn’t been started yet. You could also have the spawned task send a message back to this process signaling that it has started the server, then use a receive in this process to wait before `cast`ing. That last one is what I would probably do.

---

_[View the full topic](https://forum.elixirforum.com/t/genserver-blocking-in-async-task/32635)._
