Created
May 28, 2013 10:11
-
-
Save simonkro/5661785 to your computer and use it in GitHub Desktop.
Untested ...
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
class ThreadSafeWrapper < Delegator | |
def initialize(obj) | |
super | |
@mutex = Mutex.new | |
end | |
def method_missing(m, *args, &block) | |
@mutex.synchronize { super } | |
end | |
def __getobj__ | |
@delegate | |
end | |
def __setobj__(obj) | |
@delegate = obj | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment