|
1 | 1 | import gears.async.{Async, Future, Task, TaskSchedule, uninterruptible}
|
2 | 2 | import gears.async.default.given
|
3 |
| -import gears.async.Future.{*:, Promise, zip} |
| 3 | +import gears.async.Future.{Promise, zip} |
4 | 4 | import gears.async.AsyncOperations.*
|
5 | 5 |
|
6 | 6 | import java.util.concurrent.CancellationException
|
@@ -215,40 +215,40 @@ class FutureBehavior extends munit.FunSuite {
|
215 | 215 | assertEquals(zombieModifiedThis, true)
|
216 | 216 | }
|
217 | 217 |
|
218 |
| - test("zip on tuples with EmptyTuple") { |
219 |
| - Async.blocking: |
220 |
| - val z1 = Future { sleep(500); 10 } *: Future { sleep(10); 222 } *: Future { sleep(150); 333 } *: Future { |
221 |
| - EmptyTuple |
222 |
| - } |
223 |
| - assertEquals(z1.await, (10, 222, 333)) |
224 |
| - } |
225 |
| - |
226 |
| - test("zip on tuples with last zip") { |
227 |
| - Async.blocking: |
228 |
| - val z1 = Future { 10 } *: Future { 222 }.zip(Future { 333 }) |
229 |
| - assertEquals(z1.await, (10, 222, 333)) |
230 |
| - } |
231 |
| - |
232 |
| - test("zip(3) first error") { |
233 |
| - for (_ <- 1 to 20) |
234 |
| - Async.blocking: |
235 |
| - val e1 = AssertionError(111) |
236 |
| - val e2 = AssertionError(211) |
237 |
| - val e3 = AssertionError(311) |
238 |
| - assertEquals( |
239 |
| - (Future { |
240 |
| - sleep(Random.between(200, 300)); |
241 |
| - throw e1 |
242 |
| - } *: Future { |
243 |
| - sleep(Random.between(200, 300)); |
244 |
| - throw e2 |
245 |
| - } *: Future { |
246 |
| - sleep(Random.between(50, 100)); |
247 |
| - throw e3 |
248 |
| - } *: Future.now(Success(EmptyTuple))).awaitResult, |
249 |
| - Failure(e3) |
250 |
| - ) |
251 |
| - } |
| 218 | + // test("zip on tuples with EmptyTuple") { |
| 219 | + // Async.blocking: |
| 220 | + // val z1 = Future { sleep(500); 10 } *: Future { sleep(10); 222 } *: Future { sleep(150); 333 } *: Future { |
| 221 | + // EmptyTuple |
| 222 | + // } |
| 223 | + // assertEquals(z1.await, (10, 222, 333)) |
| 224 | + // } |
| 225 | + |
| 226 | + // test("zip on tuples with last zip") { |
| 227 | + // Async.blocking: |
| 228 | + // val z1 = Future { 10 } *: Future { 222 }.zip(Future { 333 }) |
| 229 | + // assertEquals(z1.await, (10, 222, 333)) |
| 230 | + // } |
| 231 | + |
| 232 | + // test("zip(3) first error") { |
| 233 | + // for (_ <- 1 to 20) |
| 234 | + // Async.blocking: |
| 235 | + // val e1 = AssertionError(111) |
| 236 | + // val e2 = AssertionError(211) |
| 237 | + // val e3 = AssertionError(311) |
| 238 | + // assertEquals( |
| 239 | + // (Future { |
| 240 | + // sleep(Random.between(200, 300)); |
| 241 | + // throw e1 |
| 242 | + // } *: Future { |
| 243 | + // sleep(Random.between(200, 300)); |
| 244 | + // throw e2 |
| 245 | + // } *: Future { |
| 246 | + // sleep(Random.between(50, 100)); |
| 247 | + // throw e3 |
| 248 | + // } *: Future.now(Success(EmptyTuple))).awaitResult, |
| 249 | + // Failure(e3) |
| 250 | + // ) |
| 251 | + // } |
252 | 252 |
|
253 | 253 | test("cancelled futures return the same constant CancellationException with no stack attached".ignore) {
|
254 | 254 | Async.blocking:
|
@@ -434,4 +434,17 @@ class FutureBehavior extends munit.FunSuite {
|
434 | 434 | assert(!lastFutureFinished)
|
435 | 435 | }
|
436 | 436 |
|
| 437 | + test("uninterruptible should continue even when Future is cancelled") { |
| 438 | + Async.blocking: |
| 439 | + val ch = gears.async.UnboundedChannel[Int]() |
| 440 | + val reader = Future: |
| 441 | + gears.async.uninterruptible: |
| 442 | + val i = ch.read().right.get |
| 443 | + println(i) |
| 444 | + reader.cancel() |
| 445 | + ch.sendImmediately(1) |
| 446 | + ch.sendImmediately(2) |
| 447 | + reader.awaitResult |
| 448 | + assertEquals(ch.read(), Right(2)) |
| 449 | + } |
437 | 450 | }
|
0 commit comments