I was trying to implement a callback mechanism in JRuby that looks like
@b=; @data = 1;
@b << b;
@b.each do |b|
puts “calling listener”
puts “done calling listener”
engine = Engine.new;
engine.add_listener do |data|
if data == 1
puts “data is 1”
# do something else
This code works fine with Ruby but not with JRuby 1.1.6. The code jumps
right out of the b.call(@data) and LocalJumpError was never getting
thrown. Some googling shows that there were several bugs filed against
this so I suppose this is a known issue. But my question is, what would
be the best work around for this?
- I suppose I can ask caller to always pass in a lambda to my
add_listener function, but that makes the syntax looks ugly for the
- I suppose I can ask add_listener caller not to use return in their
block or thrown some special exception to terminate their code. But
this could be ugly too.
Any other possible options or workarounds?