Hello people. I'm using Jester to build a WebSocket endpoint and I need to store my WebSockets' connections into a collection. I decided to use a HashSet and I have this piece of code:
import asyncdispatch, jester
import ws, ws/jester_extra
import std/sets
var socketPool = initHashSet[WebSocket]()
router cnsRouter:
get "/sub":
var ws = await newWebSocket(request)
socketPool.incl(ws)
while ws.readyState == Open:
discard
socketPool.excl(ws)
But it gives me error when I do the incl method call:
/path/to/project/cns/src/router.nim(13, 8) template/generic instantiation of `router` from here
/home/user/.nimble/pkgs/jester-0.5.0/jester.nim(1304, 35) template/generic instantiation of `async` from here
/path/to/project//cns/src/router.nim(16, 15) template/generic instantiation of `incl` from here
/home/user/.choosenim/toolchains/nim-1.6.8/lib/pure/collections/setimpl.nim(49, 21) template/generic instantiation of `rawGet` from here
/home/user/.choosenim/toolchains/nim-1.6.8/lib/pure/collections/hashcommon.nim(74, 14) template/generic instantiation of `genHashImpl` from here
/home/user/.choosenim/toolchains/nim-1.6.8/lib/pure/collections/hashcommon.nim(64, 12) Error: type mismatch: got <WebSocket>
but expected one of:
proc hash(sBuf: string; sPos, ePos: int): Hash
first type mismatch at position: 1
required type for sBuf: string
but expression 'key' is of type: WebSocket
proc hash(x: cstring): Hash
first type mismatch at position: 1
required type for x: cstring
but expression 'key' is of type: WebSocket
proc hash(x: float): Hash
first type mismatch at position: 1
required type for x: float
but expression 'key' is of type: WebSocket
proc hash(x: pointer): Hash
first type mismatch at position: 1
required type for x: pointer
but expression 'key' is of type: WebSocket
proc hash(x: string): Hash
first type mismatch at position: 1
required type for x: string
but expression 'key' is of type: WebSocket
proc hash[A](aBuf: openArray[A]; sPos, ePos: int): Hash
first type mismatch at position: 1
required type for aBuf: openArray[A]
but expression 'key' is of type: WebSocket
proc hash[A](s: HashSet[A]): Hash
first type mismatch at position: 1
required type for s: HashSet[hash.A]
but expression 'key' is of type: WebSocket
proc hash[A](s: OrderedSet[A]): Hash
first type mismatch at position: 1
required type for s: OrderedSet[hash.A]
but expression 'key' is of type: WebSocket
proc hash[A](x: openArray[A]): Hash
first type mismatch at position: 1
required type for x: openArray[A]
but expression 'key' is of type: WebSocket
proc hash[A](x: set[A]): Hash
first type mismatch at position: 1
required type for x: set[A]
but expression 'key' is of type: WebSocket
proc hash[T: Ordinal | enum](x: T): Hash
first type mismatch at position: 1
required type for x: T: Ordinal or enum
but expression 'key' is of type: WebSocket
proc hash[T: tuple | object | proc](x: T): Hash
first type mismatch at position: 1
required type for x: T: tuple or object or proc
but expression 'key' is of type: WebSocket
proc hash[T](x: ptr [T]): Hash
first type mismatch at position: 1
required type for x: ptr T
but expression 'key' is of type: WebSocket
I initially thought it was due to some mismatch on types but I tried the same thing but with int and string and it works perfectly. I don't really know what's going on because I'm not that experienced in Nim and this is actually the first time I'm using for a production web service.
I will appreciate every comment! Thanks