Last active
December 29, 2015 09:09
-
-
Save RichardVickerstaff/7648206 to your computer and use it in GitHub Desktop.
This shows celluloid actors do not block
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 'hollywood' | |
require 'prime' | |
class Blocker | |
def update message | |
start_time = Time.now | |
primes = [] | |
Prime.each(7777777) do |prime| | |
primes << prime | |
end | |
end_time = Time.now | |
puts '*********************************' | |
puts "Done in #{end_time - start_time}" | |
puts '*********************************' | |
end | |
end | |
class GetsBlocked | |
def initialize | |
@time = Time.now | |
end | |
def update message | |
puts "I'm still alive #{Time.now - @time}" | |
@time = Time.now | |
end | |
end | |
class Marsheller < Hollywood::Marshaller | |
supervise Hollywood::Pulse, | |
as: :pulse, | |
args: ['pulse',interval: 2] | |
supervise Hollywood::MessagingWrapper, | |
as: :blocker, | |
args: [Blocker.new, 'pulse', 'blocker'] | |
supervise Hollywood::MessagingWrapper, | |
as: :gets_blocked, | |
args: [GetsBlocked.new, 'pulse', 'gets_blocked'] | |
end | |
Marsheller.run |
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 'hollywood' | |
class Blocker | |
def update message | |
while true do | |
end | |
pust "**************************" | |
pust "Will never get here" | |
pust "**************************" | |
end | |
end | |
class GetsBlocked | |
def update message | |
puts "I'm still alive #{Time.now}" | |
end | |
end | |
class Marsheller < Hollywood::Marshaller | |
supervise Hollywood::Pulse, | |
as: :pulse, | |
args: ['pulse',interval: 2] | |
supervise Hollywood::MessagingWrapper, | |
as: :blocker, | |
args: [Blocker.new, 'pulse', 'blocker'] | |
supervise Hollywood::MessagingWrapper, | |
as: :gets_blocked, | |
args: [GetsBlocked.new, 'pulse', 'gets_blocked'] | |
end | |
Marsheller.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment