Created
April 19, 2012 20:32
-
-
Save cararemixed/2423960 to your computer and use it in GitHub Desktop.
An experimental Celluloid::ActorProxy patch.
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
module Celluloid | |
class ActorProxy | |
private | |
def def_async(method) | |
impl = ->(*a, &b) {Actor.async @mailbox, method, *a, &b} | |
ActorProxy.class_eval {define_method("#{method}!", &impl)} | |
impl | |
end | |
def def_sync(method) | |
impl = ->(*a, &b) {Actor.call @mailbox, method, *a, &b} | |
ActorProxy.class_eval {define_method(method, &impl)} | |
impl | |
end | |
# method_missing black magic to call bang predicate methods asynchronously | |
def method_missing(method, *args, &block) | |
# bang methods are async calls | |
if method.match(/(.*)!$/) | |
def_async($1).call(*args, &block) | |
else | |
def_sync(method).call(*args, &block) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment