Module: Ruff::Standard::Async

Defined in:
lib/ruff/standard/async.rb

Overview

Async provides effects Async.async, Async.yield and Async.await, and the implementation async/await. This implementation is based on the tutorial for Multicore OCaml. The module has an instance of Instance and provides its methods as module method.

Examples:

Async.with do
  task = lambda { |name|
    lambda {
      puts "Starting #{name}"
      v = (Random.rand * (10**3)).floor
      puts "Yielding #{name}"
      Async.yield
      puts "Eidnig #{name} with #{v}"

      v
    }
  }

  pa = Async.async(task.call('a'))
  pb = Async.async(task.call('b'))
  pc = Async.async lambda {
    Async.await(pa) + Async.await(pb)
  }

  puts "sum is #{Async.await pc}"
end
#==>
# Starting a
# Yielding a
# Eidnig a with 423
# Starting b
# Yielding b
# Eidnig b with 793
# sum is 1216

See Also:

Defined Under Namespace

Classes: Instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#effObject (readonly)



181
182
183
# File 'lib/ruff/standard/async.rb', line 181

def eff
  @eff
end

Class Method Details

.async(asynth) ⇒ Object



159
160
161
# File 'lib/ruff/standard/async.rb', line 159

def async(asynth)
  @inst.async asynth
end

.await(p) ⇒ Object



164
165
166
# File 'lib/ruff/standard/async.rb', line 164

def await(p)
  @inst.await p
end

.with(&th) ⇒ Object



174
175
176
# File 'lib/ruff/standard/async.rb', line 174

def with(&th)
  @inst.with(&th)
end

.yieldObject



169
170
171
# File 'lib/ruff/standard/async.rb', line 169

def yield
  @inst.yield
end