Elixir Language

Task

Syntax#

  • Task.async(fun)
  • Task.await(task)

Parameters#

Parameter Details
fun The function that should be executed in a separate process.
task The task returned by Task.async.
## Doing work in the background
task = Task.async(fn -> expensive_computation end)
do_something_else
result = Task.await(task)

Parallel processing

crawled_site = ["https://www.google.com", "https://www.stackoverflow.com"]
|> Enum.map(fn site -> Task.async(fn -> crawl(site) end) end)
|> Enum.map(&Task.await/1)

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow