Class: Threadless::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/threadless.rb

Overview

This replaces the metal body piece. It intercepts all messages and adjusts “close” in such a way that close closes the original body, and then executes all the procs that are passed into the c’tor.

Instance Method Summary collapse

Constructor Details

#initialize(body, procs) ⇒ Executor

Returns a new instance of Executor.



53
54
55
# File 'lib/threadless.rb', line 53

def initialize(body, procs)
  @body, @procs = body, procs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



49
50
51
# File 'lib/threadless.rb', line 49

def method_missing(sym, *args, &block)
  @body.__send__ sym, *args, &block
end

Instance Method Details

#closeObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/threadless.rb', line 57

def close
  return if @closed
  @closed = true
  
  @body.close if @body.respond_to?(:close)

  @procs.each do |proc| 
    proc.call
  end
end