-
-
Save jmettraux/33683 to your computer and use it in GitHub Desktop.
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 A | |
def initialize | |
@on_exception = lambda {} | |
@t = Thread.new do | |
count = 0 | |
loop do | |
begin | |
puts count | |
count += 1 | |
sleep 5 | |
raise "beuze" if count % 7 == 0 | |
rescue Exception => e | |
@on_exception.call(e) | |
end | |
end | |
end | |
end | |
def on_exception (&block) | |
@on_exception = block | |
end | |
def join | |
@t.join | |
end | |
end | |
a = A.new | |
a.on_exception { |e| | |
puts "exception : #{e}" | |
} | |
a.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment