diff --git a/lib/goru/routines/io.rb b/lib/goru/routines/io.rb index bf1dd90..4d640fa 100644 --- a/lib/goru/routines/io.rb +++ b/lib/goru/routines/io.rb @@ -161,6 +161,13 @@ def unbridge @reactor.wakeup end + # [public] + # + def finished(...) + @io.close + super + end + private def status_changed case @status when Routine::STATUS_FINISHED diff --git a/spec/features/io/closing_spec.rb b/spec/features/io/closing_spec.rb new file mode 100644 index 0000000..b1f299c --- /dev/null +++ b/spec/features/io/closing_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "goru/scheduler" + +RSpec.describe "closing the io object" do + let(:scheduler) { + Goru::Scheduler.new + } + + let(:io) { + double(:io) + } + + it "closes the io when the routine is finished" do + expect(io).to receive(:close) + + scheduler.go(intent: :read, io: io) { |routine| + routine.finished + } + + scheduler.wait + end +end