Class: Celluloid::Future::Runner

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/vendor/celluloid/lib/celluloid/future.rb

Overview

Runner is an internal class which executes the given block/method

Constant Summary

Constants included from Celluloid

VERSION

Instance Method Summary collapse

Methods included from Celluloid

#abort, actor?, #after, #alive?, #async, current, current_actor, #current_actor, included, #inspect, #link, #linked_to?, #links, #method_missing, #notify_link, #notify_unlink, #receive, receive, #signal, sleep, #sleep, #tasks, tasks, #terminate, #unlink, version, #wait, #wrapped_object

Constructor Details

#initialize(*args, &block) ⇒ Runner

Returns a new instance of Runner.



38
39
40
41
42
# File 'lib/vendor/celluloid/lib/celluloid/future.rb', line 38

def initialize(*args, &block)
  @args, @block = args, block
  @called = nil
  @error = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Celluloid

Instance Method Details

#runObject



44
45
46
47
48
49
50
51
# File 'lib/vendor/celluloid/lib/celluloid/future.rb', line 44

def run
  @value = @block.call(*@args)
rescue Exception => error
  @error = error
ensure
  @called = true
  signal :finished
end

#valueObject



53
54
55
56
57
# File 'lib/vendor/celluloid/lib/celluloid/future.rb', line 53

def value
  wait :finished unless @called
  abort @error if @error
  @value
end