Closed bung87 closed 2 years ago
This is caused by your proc being async
.
See https://github.com/yglukhov/asyncthreadpool/issues/5
Use non-async proc for expected results
I now cast types, but still asyncthreadpool not work as I expected.
I don't understand what value you want to cast.
The issue comes from the compiler handling return type of async proc differently.
Change processRequest definition and remove the async and it should be fine :
proc processRequest(
req: Request,
): Future[bool] {.async.} =
The underlying question (and perhaps I shouldn't have closed my issue) is should a threadpool be able to handle async proc ? It's not obvious that it should but you'd want @yglukhov thoughts on the matter.
the readme clam use await for async proc , while the return type cant inferred , in this case assign the returns to variable a
, when I call if a
, if will trigger type doesn't match, so I casting it, I still get copyAux error when channel send back , like I did tried use threads and channels without asyncthreadpool
. no magic lib just like go's go routine that I only need call go
some proc.
The spawned proc has to be synchronous. Whatever it returns is then wrapped into future by the threadpool.
Note: in async functions you should use await instead of waitFor.
I think this sentence in the Readme is what @bung87 is referring to.
It should be clarified whether or not async works with thread pool
Maybe the readme is confusing, let me explain.
await
or waitFor
depending if you're spawning from within an async
proc or not.waitFor
.Does that make sense?
much clear, thanks!
Feel free to add to the readme, if needed
cmd:
nim c -d:ChronosAsync --threads:on tests/tstreamserver.nim
https://github.com/bung87/scorper/blob/36aa15fc662718c07065306c0c95b735763c47f1/src/scorper/http/streamserver.nim#L858
Error: type mismatch: got <RetType
gensym817>`