Created
April 8, 2018 03:27
-
-
Save leandrob13/b325d5dd0fa630a256bafbf8113d0183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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