Last active
August 29, 2015 14:19
-
-
Save Burgestrand/d2a88d15c22618ebf175 to your computer and use it in GitHub Desktop.
Celluloid, exclusive, and blocks executed on receiver
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
source "https://rubygems.org" | |
gem "celluloid", github: "celluloid/celluloid", branch: "master" |
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
GIT | |
remote: git://github.com/celluloid/celluloid.git | |
revision: 9c28a6825cbdf4b916540caad82b17126c1f8945 | |
branch: master | |
specs: | |
celluloid (0.16.0) | |
timers (~> 4.0.0) | |
GEM | |
remote: https://rubygems.org/ | |
specs: | |
hitimes (1.2.2) | |
timers (4.0.1) | |
hitimes | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
celluloid! |
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 "bundler/setup" | |
require "celluloid" | |
Celluloid.logger = nil | |
class A | |
include Celluloid | |
def on_caller | |
b = B.new | |
b.on_caller { } | |
end | |
def exclusive_on_caller | |
b = B.new | |
exclusive do | |
b.on_caller { } | |
end | |
end | |
def on_receiver | |
b = B.new | |
b.on_receiver { } | |
end | |
def exclusive_on_receiver | |
b = B.new | |
exclusive do | |
b.on_receiver { } | |
end | |
end | |
end | |
class B | |
include Celluloid | |
def on_caller(&block) | |
yield | |
puts "> B#on_caller #{block.inspect}" | |
end | |
def on_receiver(&block) | |
yield | |
puts "> B#on_receiver #{block.inspect}" | |
end | |
execute_block_on_receiver :on_receiver | |
end | |
A.new.on_caller | |
$stderr.puts "OK: #on_caller" | |
begin | |
A.new.exclusive_on_caller | |
rescue => error | |
$stderr.puts "OK: #exclusive_on_caller (#{error})" | |
end | |
A.new.on_receiver | |
$stderr.puts "OK: #on_receiver" | |
begin | |
A.new.exclusive_on_receiver | |
rescue => error | |
$stderr.puts "ERROR: #exclusive_on_receiver (#{error})" | |
else | |
$stderr.puts "OK: #exclusive_on_receiver" | |
end |
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 "bundler/setup" | |
require "celluloid" | |
Celluloid.logger = nil | |
class A | |
include Celluloid | |
def exclusive_on_receiver | |
b = B.new | |
exclusive { b.on_receiver { $stderr.puts "OK" } } | |
end | |
end | |
class B | |
include Celluloid | |
execute_block_on_receiver def on_receiver(&block) | |
yield | |
end | |
end | |
begin | |
A.new.exclusive_on_receiver | |
rescue => error | |
$stderr.puts "ERROR: #exclusive_on_receiver (#{error})" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment