Skip to content

Commit

Permalink
Close the io object when the routine is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanp committed Sep 17, 2023
1 parent 98ce98e commit 9edae80
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 9edae80

Please sign in to comment.