summary refs log tree commit diff stats
path: root/tests/arc/torcmisc.nim
blob: e41ad7c77305f50695d89c8f9b20c9242a60115e (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
discard """
  output: '''success'''
  cmd: "nim c --gc:orc -d:release $file"
"""

# bug #17170

when true:
  import asyncdispatch

  type
    Flags = ref object
      returnedEof, reading: bool

  proc dummy(): Future[string] {.async.} =
    result = "foobar"

  proc hello(s: Flags) {.async.} =
    let buf =
      try:
        await dummy()
      except CatchableError as exc:
        # When an exception happens here, the Bufferstream is effectively
        # broken and no more reads will be valid - for now, return EOF if it's
        # called again, though this is not completely true - EOF represents an
        # "orderly" shutdown and that's not what happened here..
        s.returnedEof = true
        raise exc
      finally:
        s.reading = false

  waitFor hello(Flags())
  echo "success"

# bug #18240
import tables

type
  TopicHandler* = proc(topic: string,
                       data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].}

  PeerID* = object
    data*: seq[byte]

  PeerInfo* = ref object of RootObj
    peerId*: PeerID

  Connection* = ref object of RootObj
    peerInfo*: PeerInfo

  PubSubPeer* = ref object of RootObj
    codec*: string

  PubSub* = ref object of RootObj
    topics*: Table[string, seq[TopicHandler]]
    peers*: Table[PeerID, PubSubPeer]

proc getOrCreatePeer*(myParam: PubSub, peerId: PeerID, protos: seq[string]): PubSubPeer =
  myParam.peers.withValue(peerId, peer):
    return peer[]

method handleConn*(myParam: PubSub,
                  conn: Connection,
                  proto: string) {.base, async.} =
  myParam.peers.withValue(conn.peerInfo.peerId, peer):
    let peerB = peer[]