Skip to content

Commit 57ff01b

Browse files
authored
Merge pull request scalacenter#1834 from dos65/fix_timeoutTo
fix: bloop.task.Task - avoid materializing fallback task in timeoutTo
2 parents 573d26b + 2da3ca3 commit 57ff01b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

backend/src/main/scala/bloop/task/Task.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ sealed trait Task[+A] { self =>
164164
Task
165165
.chooseFirstOf(
166166
self,
167-
Task.sleep(duration).flatMap(_ => backup)
167+
Task.sleep(duration)
168168
)
169-
.map {
170-
case Left((a, _)) => a
171-
case Right((_, b)) => b
169+
.flatMap {
170+
case Left((a, _)) =>
171+
Task.now(a)
172+
case Right((a, _)) =>
173+
a.cancel()
174+
backup
172175
}
173176
}
174177

backend/src/test/scala/bloop/task/TaskSpec.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,15 @@ class TaskSpec {
183183

184184
}
185185

186+
@Test
187+
def timeoutTo2: Unit = {
188+
val ref = new AtomicBoolean(true)
189+
val t1 = Task.unit.delayExecution(500.milli)
190+
val t2 = Task(ref.set(false))
191+
val withTimeout = t1.timeoutTo(1.second, t2)
192+
193+
Await.result((withTimeout *> Task.sleep(2.seconds)).runAsync, 3.second)
194+
assertEquals(true, ref.get())
195+
}
196+
186197
}

0 commit comments

Comments
 (0)