Skip to content

Instantly share code, notes, and snippets.

@shotat
Last active September 18, 2016 09:54
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 shotat/cc1f3fa8e1e924aa3a83cd2b9b568837 to your computer and use it in GitHub Desktop.
Save shotat/cc1f3fa8e1e924aa3a83cd2b9b568837 to your computer and use it in GitHub Desktop.
Lock.rb
class Lock
def self.acquire
lock = new # リソース初期化
lock.exclusive_lock!
if block_given?
yield(lock)
else
lock
end
ensure
if block_given?
lock.unlock if lock
end
end
end
Lock.acquire do |lock|
puts lock
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment