Skip to content

Commit

Permalink
Merge pull request #3290 from durban/issue3283
Browse files Browse the repository at this point in the history
Fix #3283: make Deferred#complete uncancelable
  • Loading branch information
djspiewak authored Nov 29, 2022
2 parents c7ee009 + 4b73c7a commit 88170b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ object Deferred {
}
}

F.defer(loop())
F.uncancelable(_ => F.defer(loop()))
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/shared/src/test/scala/cats/effect/kernel/DeferredSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,20 @@ class DeferredSpec extends BaseSpec { outer =>
}
}

"issue #3283: complete must be uncancelable" in real {

import cats.syntax.all._

for {
d <- Deferred[IO, Int]
attemptCompletion = { (n: Int) => d.complete(n).void }
res <- List(
IO.race(attemptCompletion(1), attemptCompletion(2)).void,
d.get.void
).parSequence
r <- IO { (res == List((), ())) must beTrue }
} yield r
}

}
}

0 comments on commit 88170b9

Please sign in to comment.