Best way to run a non-blocking async function from a GenServer?

I’ve been using the Task and Task.Supervisor utilities, but haven’t found the best way to handle creating a non-blocking, unlinked async function from a GenServer.

I basically just wanted to run a function that would return a response to the GenServer – but not crash if it failed… and not block incoming calls.

I can kind of handle it using Task.start and Process.send to reply – but assume there’s something better I am missing?

Thanks,
Scott

Have a task supervisor, start the task under the task supervisor with async_nolink and then receive the result in handle info. Here’s an example within the docs: https://hexdocs.pm/elixir/Task.Supervisor.html#async_nolink/3

4 Likes

Thanks so much!!! – I missed that one! :slight_smile:

1 Like