Module: Elixir::Task

Defined in:
lib/elixir/task.rb

Constant Summary collapse

POOL =
Concurrent::FixedThreadPool.new Concurrent.processor_count + 2

Class Method Summary collapse

Class Method Details

.async(fun) ⇒ Object



10
11
12
13
14
15
# File 'lib/elixir/task.rb', line 10

def async fun
  fun.extend Concurrent::Async
  fun.init_mutex

  fun.async.call
end

.await(task, timeout = 5000) ⇒ Object



17
18
19
20
21
22
# File 'lib/elixir/task.rb', line 17

def await task, timeout = 5000
  value = task.value timeout / 1000
  task.fail && raise(StandardError, 'time out') if task.pending?

  value
end

.start(fun) ⇒ Object



24
25
26
# File 'lib/elixir/task.rb', line 24

def start fun
  POOL << fun
end