Module: Concurrent::Futures

Included in:
Future
Defined in:
lib/concurrent/futures.rb,
ext/concurrent/futures/futures.c

Defined Under Namespace

Modules: Future Classes: AsyncError, Lazy, Promise, Ref

Constant Summary collapse

AlreadyFulfilledError =
Class.new StandardError

Instance Method Summary collapse

Instance Method Details

#async(&block) ⇒ Object Also known as: spawn, future



34
35
36
# File 'lib/concurrent/futures.rb', line 34

def async( &block )
  Thunk.new( Thread.new( &block ) )
end

#await(future) ⇒ Object



40
41
42
# File 'lib/concurrent/futures.rb', line 40

def await( future )
  Thunk.value future
end

#await_any(*futures) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/concurrent/futures.rb', line 44

def await_any( *futures )
  threads = futures.map { |future| Thread.new { Futures::await future } }
  begin
    threads.index ThreadsWait.new( *threads ).wait_next
  ensure
    threads.each { |thread| thread.raise RuntimeError }
  end
end

#lazy(&block) ⇒ Object



121
122
123
# File 'lib/concurrent/futures.rb', line 121

def lazy( &block )
  Thunk.new( Lazy.new( &block ) )
end