Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Created December 8, 2008 23:36
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 jmettraux/33683 to your computer and use it in GitHub Desktop.
Save jmettraux/33683 to your computer and use it in GitHub Desktop.
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