summary refs log tree commit diff stats
path: root/tests/notnil/tnotnil5.nim
blob: 2dcb7f7c3eac9e75f36861a3683dfd888fd5c17b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)