tnotnil5.nim 466 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. matrix: "--threads:on"
  3. """
  4. {.experimental: "parallel".}
  5. {.experimental: "notnil".}
  6. import threadpool
  7. type
  8. AO = object
  9. x: int
  10. A = ref AO not nil
  11. proc process(a: A): A =
  12. return A(x: a.x+1)
  13. proc processMany(ayys: openArray[A]): seq[A] =
  14. var newAs: seq[FlowVar[A]]
  15. parallel:
  16. for a in ayys:
  17. newAs.add(spawn process(a))
  18. for newAflow in newAs:
  19. let newA = ^newAflow
  20. if isNil(newA):
  21. return @[]
  22. result.add(newA)