mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 13:07:48 +00:00
29 lines
466 B
Nim
29 lines
466 B
Nim
discard """
|
|
matrix: "--threads:on"
|
|
"""
|
|
|
|
{.experimental: "parallel".}
|
|
{.experimental: "notnil".}
|
|
import threadpool
|
|
|
|
type
|
|
AO = object
|
|
x: int
|
|
|
|
A = ref AO not nil
|
|
|
|
proc process(a: A): A =
|
|
return A(x: a.x+1)
|
|
|
|
proc processMany(ayys: openArray[A]): seq[A] =
|
|
var newAs: seq[FlowVar[A]]
|
|
|
|
parallel:
|
|
for a in ayys:
|
|
newAs.add(spawn process(a))
|
|
for newAflow in newAs:
|
|
let newA = ^newAflow
|
|
if isNil(newA):
|
|
return @[]
|
|
result.add(newA)
|