otp
otp copied to clipboard
Add `await_many` and related functions
For running many tasks in parallel, it is complicated to get a solid solution, for example:
pub fn parallel(make_tasks: List(fn() -> a), timeout: Int) -> List(a) {
make_tasks
|> list.map(fn(make_task) { task.async(make_task) })
|> list.map(fn(t) { task.await(t, timeout) })
}
Works but the timeouts will be run in sequence which is not what you really want.
It has been mentioned in discord a few times too:
- https://discord.com/channels/768594524158427167/768594524158427170/1287851279925907509
- https://discord.com/channels/768594524158427167/768594524158427170/1079034165024014388
Some of these functions have been added in v0.13
Since the task module has been removed, this issue should be closed or moved.