Task

Other topics

Doing work in the background

task = Task.async(fn -> expensive_computation end)
do_something_else
result = Task.await(task)

Parallel processing

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

Syntax:

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

Parameters:

ParameterDetails
funThe function that should be executed in a separate process.
taskThe task returned by Task.async.

Contributors

Topic Id: 7588

Example Ids: 24990,24991

This site is not affiliated with any of the contributors.