torcmisc.nim 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. discard """
  2. output: '''success'''
  3. cmd: "nim c --gc:orc -d:release $file"
  4. """
  5. # bug #17170
  6. when true:
  7. import asyncdispatch
  8. type
  9. Flags = ref object
  10. returnedEof, reading: bool
  11. proc dummy(): Future[string] {.async.} =
  12. result = "foobar"
  13. proc hello(s: Flags) {.async.} =
  14. let buf =
  15. try:
  16. await dummy()
  17. except CatchableError as exc:
  18. # When an exception happens here, the Bufferstream is effectively
  19. # broken and no more reads will be valid - for now, return EOF if it's
  20. # called again, though this is not completely true - EOF represents an
  21. # "orderly" shutdown and that's not what happened here..
  22. s.returnedEof = true
  23. raise exc
  24. finally:
  25. s.reading = false
  26. waitFor hello(Flags())
  27. echo "success"
  28. # bug #18240
  29. import tables
  30. type
  31. TopicHandler* = proc(topic: string,
  32. data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].}
  33. PeerID* = object
  34. data*: seq[byte]
  35. PeerInfo* = ref object of RootObj
  36. peerId*: PeerID
  37. Connection* = ref object of RootObj
  38. peerInfo*: PeerInfo
  39. PubSubPeer* = ref object of RootObj
  40. codec*: string
  41. PubSub* = ref object of RootObj
  42. topics*: Table[string, seq[TopicHandler]]
  43. peers*: Table[PeerID, PubSubPeer]
  44. proc getOrCreatePeer*(myParam: PubSub, peerId: PeerID, protos: seq[string]): PubSubPeer =
  45. myParam.peers.withValue(peerId, peer):
  46. return peer[]
  47. method handleConn*(myParam: PubSub,
  48. conn: Connection,
  49. proto: string) {.base, async.} =
  50. myParam.peers.withValue(conn.peerInfo.peerId, peer):
  51. let peerB = peer[]