For example: I have a process that streams audio over a websocket. It reads a file, and then sends chunks of audio one at a time with a Process.sleep in between each chunk to ensure the audio data is sent at the right speed:
def send_file(pid, path) do {:ok, data} = File.read(path) data |> Enum.chunk_every(@chunk_size) |> Enum.each(fn chunk -> WebSockex.send_frame(pid, chunk) Process.sleep(@delay_ms) end) end
I know that I could avoid the sleep by using e.g. Process.send_after. But I want to understand more generally if blocking like this is considered bad practice, and if so, why?
If I run the above code in a separate task, nothing else in my app will be blocked, so it seems like it shouldn't be a problem.