Alright, I've finally figured out async and threads, I just need to figure out how I can run downloadFile in a threaded proc.
I don't want to change any code in the nim source to make this happen, I've done a lot of browsing and I can't come up with anything that doesn't involve changing the compilers source code. The error:
'ThreadedDownload' is not GC-safe as it accesses 'defaultSSLContext' which is a global using GC'ed memory
The thing is that I most likely will need to use SSL. Even if someone can show me how to create a new SSLContext inside the threaded proc that works I'd be happy.
hcorion, its a workaround. You need to create context via
proc newContext*(protVersion = protSSLv23, verifyMode = CVerifyPeer,
certFile = "", keyFile = "", cipherList = "ALL"): SSLContext =
You can find this function in net.nim [https://github.com/nim-lang/Nim/blob/devel/lib/pure/net.nim#L309].
Do not store this context in global variable.
After that you can pass this context as argument to downloadFile.