Skip to content

Instantly share code, notes, and snippets.

@szymko
Created May 28, 2013 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szymko/5665069 to your computer and use it in GitHub Desktop.
Save szymko/5665069 to your computer and use it in GitHub Desktop.
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