Skip to content

Commit

Permalink
Merge pull request #24 from bryanp/chg/io-close
Browse files Browse the repository at this point in the history
Close the io object when the routine is finished
  • Loading branch information
bryanp authored Sep 17, 2023
2 parents 00c53e2 + 9edae80 commit f687219
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/goru/routines/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions spec/features/io/closing_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f687219

Please sign in to comment.