twaitany.nim 702 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: '''true'''
  3. """
  4. # bug #7638
  5. import threadpool, os, strformat
  6. proc timer(d: int): int =
  7. #echo fmt"sleeping {d}"
  8. sleep(d)
  9. #echo fmt"done {d}"
  10. return d
  11. var durations = [1000, 1500, 2000, 2500, 3000]
  12. var tasks: seq[FlowVarBase] = @[]
  13. var results: seq[int] = @[]
  14. for i in 0 .. durations.high:
  15. tasks.add spawn timer(durations[i])
  16. var index = blockUntilAny(tasks)
  17. while index != -1:
  18. results.add ^cast[FlowVar[int]](tasks[index])
  19. tasks.del(index)
  20. #echo repr results
  21. index = blockUntilAny(tasks)
  22. doAssert results.len == 5
  23. doAssert 1000 in results
  24. doAssert 1500 in results
  25. doAssert 2000 in results
  26. doAssert 2500 in results
  27. doAssert 3000 in results
  28. sync()
  29. echo "true"