twaitany.nim 651 B

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