I’m quite new to the Elixir community and so far hooked on the language and ecosystem. Today I read a nice article by Ryan Sydnor on how they speed up their application by parallelising database queries. He used tasks to concurrently run the expensive queries which improved performance drastically. The full article can be read here.
Elixir really shines in cases like these and I thought it would be great to have a library for simple parallelization. That’s why I created ParallelTask, a lightweight wrapper around Task making it easy to parallelize API requests, database queries, and the like.
This is my first Elixir project and any feedback is much welcomed. Thanks!
I like the idea, how you can build up the tasks to execute in parallel and then execute them together. Although since the idea is conceptually very similar to Ecto.Multi I think it would make sense to mirror that API.
So instead of:
|> ParallelTask.add(first_task: fn -> "Result from first task" end)
We could write:
|> ParallelTask.add(:first_task, fn -> "Result from first task" end)
That would also allow us to more flexibly name our tasks (Ecto.Multi actually now accepts strings)
It’s surprising that the Task module doesn’t make it easier to work with keyed tasks like this.
The closest I could get without writing a helper function is: