I ended up doing this:
proc foo() =
var nsubs = len(settings.file_list)
var responsesB = newSeq[FlowVarBase](nsubs)
var responsesT = newSeq[FlowVar[string]](nsubs)
for i in 0..<nsubs:
let fn = settings.file_list[i]
let fv: FlowVar[string] = spawn myfunc(fn)
responsesT[i] = fv
responsesB[i] = fv
while nsubs > 0:
let i = awaitAny(responsesB)
let fv: FlowVar[string] = responsesT[i]
let fn_rtn = ^fv
nsubs.dec
Is that dumb? At least it compiles.
Second problem: When myfunc immediately returns, awaitAny() just waits forever. I think there is a race condition. If I add a delay into myfunc(), this works.
So awaitAny() seems useless. Am I using it wrong? I'm going to try callbacks instead. But then should a add a final "sync()" after all callbacks are created?