socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.12k stars 86 forks source link

cannot interrupt reactor if a queue is active #258

Closed emiltin closed 1 year ago

emiltin commented 1 year ago

I found that interrupting a reactor doesn't work if a subtask is waiting for a queue.

require 'async'
require 'async/queue'

reactor = Async::Reactor.new
queue = Async::Queue.new

puts 'a'
reactor.run do |task|
  task.async do
    queue.dequeue
  end
  reactor.interrupt
end

puts 'b'
reactor.run do
  reactor.interrupt
  puts 'c'
end

puts 'd'        # this is never reached

The first interrupt works, but the second somehow doesn't.

On MacOS.

% bundle exec gem list async
*** LOCAL GEMS ***
async (2.6.2)
async-io (1.35.0)

% ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
ioquatix commented 1 year ago

Hmm, odd, I'll take a look.

ioquatix commented 1 year ago

This should be fixed, please feel free to test it and report back.

emiltin commented 1 year ago

works for me thanks!