Skip to content

Instantly share code, notes, and snippets.

@RichardVickerstaff
Last active December 29, 2015 09:09
Show Gist options
  • Save RichardVickerstaff/7648206 to your computer and use it in GitHub Desktop.
Save RichardVickerstaff/7648206 to your computer and use it in GitHub Desktop.
This shows celluloid actors do not block
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
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