tflowvar.nim 573 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. discard """
  2. matrix: "--mm:refc"
  3. output: '''foobarfoobar
  4. bazbearbazbear
  5. 1'''
  6. cmd: "nim $target --threads:on $options $file"
  7. disabled: "openbsd"
  8. """
  9. import threadpool
  10. proc computeSomething(a, b: string): string = a & b & a & b & "\n"
  11. proc main =
  12. let fvA = spawn computeSomething("foo", "bar")
  13. let fvB = spawn computeSomething("baz", "bear")
  14. echo(^fvA, ^fvB)
  15. main()
  16. sync()
  17. type
  18. TIntSeq = seq[int]
  19. proc t(): TIntSeq =
  20. result = @[1]
  21. proc p(): int =
  22. var a: FlowVar[TIntSeq]
  23. parallel:
  24. var aa = spawn t()
  25. a = aa
  26. result = (^a)[0]
  27. echo p()