I need to save a cache to disk periodically, every 500ms, how can I do that?
The code I tried is not compiled properly. Also, it seems that the asyncCheck should be used for error checking.
import tables, os, asyncdispatch
var cache = init_table[string, int]()
proc save(cache: Table[string, int]): Future[void] {.async.} =
echo cache
addTimer(
timeout = 500, oneshot = false, cb = proc() = discard cache.save()
)
for i in (0..3):
cache["a"] = i
echo cache
sleep 1000