Skip to content

Commit

Permalink
fix(timeout): channels shouldn't block
Browse files Browse the repository at this point in the history
as otherwise we would leak the fiber if there is a timeout as the channels would never receive
  • Loading branch information
stakach committed Aug 8, 2022
1 parent 74a18b3 commit 8c30a49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tasker
version: 2.0.6
version: 2.0.7
crystal: ">= 0.36.1"

dependencies:
Expand Down
10 changes: 5 additions & 5 deletions spec/tasker_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,25 @@ describe Tasker do
it "should pause and resume a repeating task" do
sched = Tasker.instance
run_count = 0
task = sched.every(40.milliseconds) { run_count += 1; run_count }
task = sched.every(80.milliseconds) { run_count += 1; run_count }

begin
tasks << task

sleep 50.milliseconds
sleep 100.milliseconds
run_count.should eq(1)

sleep 40.milliseconds
sleep 80.milliseconds
run_count.should eq(2)

task.cancel

sleep 40.milliseconds
sleep 80.milliseconds
run_count.should eq(2)

task.resume

sleep 50.milliseconds
sleep 100.milliseconds
run_count.should eq(3)
rescue error
puts "\nfailed cancel running tasks\n#{error.inspect_with_backtrace}"
Expand Down
4 changes: 2 additions & 2 deletions src/tasker/timeout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Tasker
end

def execute!
success = Channel(Output).new
failure = Channel(Exception).new
success = Channel(Output).new(1)
failure = Channel(Exception).new(1)

if @same_thread
fiber = Fiber.new { perform_action(success, failure) }
Expand Down

0 comments on commit 8c30a49

Please sign in to comment.