Giter VIP home page Giter VIP logo

parallel_task's Introduction

ParallelTask

Elixir library to run multiple functions in parallel and capture the results.

Suitable for multiple slow tasks such as API calls and database queries which can be performed concurrently. The process will be blocked until all functions have returned or the timeout has been reached.

Full documentation available on hexdocs.

Installation

The package can be installed by adding parallel_task to your list of dependencies in mix.exs:

def deps do
  [{:parallel_task, "~> 0.1.0"}]
end

Usage

Run two functions in parallel. results will be a map of keys and results.

results = ParallelTask.new
          # Add some long running tasks eg. API calls
          |> ParallelTask.add(first_task: fn -> "Result from first task" end)
          |> ParallelTask.add(second_task: fn -> "Result from second task" end)
          |> ParallelTask.perform

Use pattern matching to easily extract the results.

%{
  first_task: first_result,
  second_task: second_result
} = results

IO.puts first_result # "Result from first task"
IO.puts second_result # "Result from second task"

License

Licensed under MIT.

parallel_task's People

Contributors

fabianlindfors avatar

Watchers

Marko Anastasov avatar James Cloos avatar  avatar Milica Nerlović avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.