File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments