The following code generates a compile error and I'm confused as to why. Why doesn't the await keyword give me a string to work with in this case?
import asyncdispatch
proc fa(i: int): Future[string] =
var fut = newFuture[string]("fa")
fut.complete("fa: " & $i)
result = fut
proc fb(s: string): Future[string] =
var fut = newFuture[string]("fb")
fut.complete("fb: " & s)
result = fut
proc fc(i: int): Future[string] {.async.} =
let a = await fa(i)
result = fb(a) # <-- compile error
when isMainModule:
echo(waitFor fa(3))
echo(waitFor fb("main"))
echo(waitFor fc(3))
b1.nim(13, 35) template/generic instantiation of `async` from here
b1.nim(15, 14) Error: type mismatch: got <Future[system.string]> but expected 'string'
Nevermind, I figured it out. I thought the error was on the input to fb but it turns out the compiler was complaining about the resulting value assigned to result. Changing fc to the following fixes it.
proc fc(i: int): Future[string] {.async.} =
let a = await fa(i)
result = await fb(a)