Skip to content

Instantly share code, notes, and snippets.

@leandrob13
Created April 8, 2018 03:27
Show Gist options
  • Save leandrob13/b325d5dd0fa630a256bafbf8113d0183 to your computer and use it in GitHub Desktop.
Save leandrob13/b325d5dd0fa630a256bafbf8113d0183 to your computer and use it in GitHub Desktop.
test("TaskLocal.bind cleanup without async boundary") {
import scala.concurrent.duration.Duration
val local: TaskLocal[Boolean] = TaskLocal[Boolean](false).runSyncUnsafe(Duration.Inf)
def loop(n: Int = 1000): Task[Unit] =
if (n > 0) attempt.flatMap(_ => loop(n - 1))
else Task.unit
def attempt = local.read flatMap {
case false => local.bind(true)(Task.unit)
case true => Task.now(fail())
}
loop(5).runSyncUnsafe(Duration.Inf)
assert(!local.read.runSyncUnsafe(Duration.Inf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment