# Task.async return message

**URL:** <https://forum.elixirforum.com/t/task-async-return-message/25359>\
**Category:** Discussions\
**Tags:** book-elixir-in-action, discussion\
**Created:** [September 13, 2019, 8:03am UTC](https://forum.elixirforum.com/t/task-async-return-message/25359 "2019-09-13T08:03:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tano](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tano/32/10787_2.png) [@Tano](https://forum.elixirforum.com/u/Tano)\
**Post date:** [September 13, 2019, 8:03am UTC](https://forum.elixirforum.com/t/task-async-return-message/25359/1 "2019-09-13T08:03:05Z")

</div>

Currently I am reading Elixir In Action and it is mentioned there for Task.async that the return value of the executed lambda is sent back as a message to the starter process. I am a bit confused here or maybe missed some important part of the text, please correct me if I am wrong: it means that even if i dont care for the return value of the lambda i must have something like handle\_info to catch the message that is send back or ? Because if i dont handle the message it will just stay in the mail box forever, thanks guys

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [September 13, 2019, 8:11am UTC](https://forum.elixirforum.com/t/task-async-return-message/25359/2 "2019-09-13T08:11:22Z")

</div>

Yes. Exactly.

I’m not aware of a `Task` like thing that can be run solely for its side effects. But exactly the current behaviour of sending back “unwanted” messages makes it break applications, or at least creates a lot of confusing log messages.

@Fl4m3Ph03n1x created a lot of threads to trace down those messages, and I’m not even sure if they ever found the actual source of the stray messages.

---

<div class="post-metadata">

**Author:** ![bugant](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bugant/32/4280_2.png) [@bugant](https://forum.elixirforum.com/u/bugant)\
**Post date:** [September 13, 2019, 8:20am UTC](https://forum.elixirforum.com/t/task-async-return-message/25359/3 "2019-09-13T08:20:59Z")

</div>

Yes, it’s quite clear in the doc I’d say. See [https://hexdocs.pm/elixir/Task.html:](https://hexdocs.pm/elixir/Task.html:)

> Tasks spawned with `async` can be awaited on by their caller process (and only their caller) as shown in the example above. They are implemented by spawning a process that sends a message to the caller once the given computation is performed.

And, so `Task.await` is used to read the message sent by the task.

---

<div class="post-metadata">

**Author:** ![jwarlander](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jwarlander/32/1155_2.png) [@jwarlander](https://forum.elixirforum.com/u/jwarlander)\
**Post date:** [September 13, 2019, 8:33am UTC](https://forum.elixirforum.com/t/task-async-return-message/25359/4 "2019-09-13T08:33:06Z")

</div>

The documentation also suggests several other ways to run tasks, @Tano, if you _don’t_ want this behavior, eg. `Task.start_link/1`, `Task.start/1`, or starting tasks under a `Task.Supervisor`.

---

<div class="post-metadata">

**Author:** ![Fl4m3Ph03n1x](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/32/11709_2.png) [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Post date:** [September 30, 2019, 9:27am UTC](https://forum.elixirforum.com/t/task-async-return-message/25359/5 "2019-09-30T09:27:15Z")

</div>

> [@NobbZ](#):
>
> @Fl4m3Ph03n1x created a lot of threads to trace down those messages, and I’m not even sure if they ever found the actual source of the stray messages.

Yes, I found the processes sending the messages, but the methodology we used is not fit for production, unless you don’t mind killing a machine with all the logging or slowing it down considerably.

There are many ways of finding out which process is receiving an unhandled message, but there is no straight way. I have compiled a list of all the relevant posts I created regarding this topic for your convenience, should you ever venture this far into message passing:

- [Show all messages in process mailbox assert\_receive](https://forum.elixirforum.com/t/show-all-messages-in-process-mailbox-assert-receive/23759)
- [Find out how many unhandled messages a process received - #3 by Fl4m3Ph03n1x](https://forum.elixirforum.com/t/find-out-how-many-unhandled-messages-a-process-received/23148/3)
- [How to detect wich process is getting unexpected messages? - #7 by sasajuric](https://forum.elixirforum.com/t/how-to-detect-wich-process-is-getting-unexpected-messages/23147/7)
- [Tracing all calls to handle\_info in all processes using recon\_trace - #9 by Fl4m3Ph03n1x](https://forum.elixirforum.com/t/tracing-all-calls-to-handle-info-in-all-processes-using-recon-trace/23191/9)
- [Error when using function in recon\_trace.calls](https://forum.elixirforum.com/t/error-when-using-function-in-recon-trace-calls/23193)
- [How to use recon\_trace.calls properly?](https://forum.elixirforum.com/t/how-to-use-recon-trace-calls-properly/23198)
- [Can't get recon\_trace to work with anon function - #4 by NobbZ](https://forum.elixirforum.com/t/cant-get-recon-trace-to-work-with-anon-function/23220/4)
- [Is it possible to use Rexbug to trace messages send/received by processes? - #8 by Fl4m3Ph03n1x](https://forum.elixirforum.com/t/is-it-possible-to-use-rexbug-to-trace-messages-send-received-by-processes/23278/8)

Still, if you follow the recommendations for Task.async and Task.await, you will (hopefully) never need this information, unless you are using a 3rd party library that doesn’t follow the conventions (as was our case).
