Module: Bowline::Async::Methods

Defined in:
lib/bowline/async.rb

Instance Method Summary collapse

Instance Method Details

#async(*methods) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bowline/async.rb', line 12

def async(*methods)
  methods.each {|meth|
    define_method("#{meth}_with_async") {|*args|
      callback = nil
      if(args.last.is_a?(::RubyKMethod))
        callback = args.pop
      end
      Thread.new do
        res = send("#{meth}_without_async", *args)
        callback.call(res) if callback
      end
    }
    alias_method_chain meth, :async
  }
end