Hi all!
I have function, that does deserialization in a way, that it takes filename and type and returns complete object.
It takes too long to process sequentially couple of files, so i wanted to parallel calls, because they are not data-tied.
However, I cannot simply spawn ` thread from `threadpool library, because it says
Error: cannot create a FlowVar of type: *here is my complex type*
How can i bypass this in a graceful way?
I guess i doing something wrong, because i tried it like this:
proc deserialize[T](filename: string): ref T =
read_file(filename).to[:T]
let obj = spawn deserialize[A]("my_file.json")
And it says:
Error: type mismatch: got <A> but expected 'ref A'
proc deserialize[T](filename: string): ref T =
new(result)
result[] = readFile(filename).to[:T]
let obj = spawn deserialize[A]("my_file.json")
I solved my problem like this:
proc deserialize[T](filename: string): ref T =
let obj = read_file(filename).to[:T]
result = new T
result[] = obj
let obj = spawn deserialize[A]("my_file.json")
But i find it ugly, isn't it? Extra copy operation