I am reading the book Programming Phoenix 1.4. There is a task, we want to connect Wolfram API, and if it does not respond within 10 second, kill the process:
backends
|> Enum.map(&async_query(&1, query, opts))
|> Task.yield_many(timeout)
|> Enum.map(fn {task, res} -> res || Task.shutdown(task, :brutal_kill) end)
But wouldn’t it be easier to specify a timeout for :httpc
and let the process terminate normally? Maybe there is a best practice for killing such a process or it was made for illustration purposes?