Created
May 28, 2013 18:42
-
-
Save szymko/5665069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'celluloid' | |
module Simulation | |
module Asynchronous | |
def self.extended(base) | |
define_method(:method_added) do |*args| | |
if args[0].to_s == "run" and not base.included_modules.member? Celluloid | |
include Celluloid | |
define_asynchronous_method(base, :run) | |
end | |
end | |
end | |
def define_asynchronous_method(base, method) | |
base.__send__(:alias_method, "#{method}_synchronous".to_sym, method) | |
base.class_eval <<-METHOD, __FILE__, __LINE__ + 1 | |
def #{method}(*args) | |
future.#{method}_synchronous | |
end | |
METHOD | |
end | |
end | |
end | |
# class A | |
# extend Simulation::Asynchronous | |
# def run | |
# sleep 2 | |
# return 15 | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment