`dbWritestatement` is a table with prepared statements. But your comment set me on track again.
Sorry for wasting your time, the code above was reduced too much. The real problem is that in the code below `(_, msg) = await dataStream.read` sits too deep in the loop(s). A `await futureStream.hasContent()` without consuming a value would be nice to have. dbWrite( dbWriteStatement: Table[string, SqlStatement], datatype: Table[string, string], dataStream: FutureStream ){.async.} = var unfinished = true queueLen:int while unfinished: queueLen = len dataStream if queueLen > 0: exec dbWriteStatement["begin"] while queuelen > 0: dec queueLen let (_, msg) = await dataStream.read smsg = msg.split(":") topic = smsg[0] payload = smsg[1] [...] dbWriteStatement[topic].exec(topic, data) [...] await sleepAsync(0) exec dbWriteStatement["commit"] await sleepAsync(0) await sleepAsync(0) if finished dataStream: unfinished = false handler() await sleepAsync(0) Run