import os,osproc,fsmonitor,strutils,times
import asyncio,net
#import asyncdispatch,asyncnet
var disp = newDispatcher()
var monitor = newMonitor()
let orgDir = "/home/lxuser/Dropbox/Test"
monitor.add(orgDir)
disp.register(monitor,proc (m: FSMonitor, ev: MonitorEvent) =
echo("Got event: " & $ev.kind & " at : " & $getLocalTime(getTime())))
proc main() =
while true:
try:
if not disp.poll(): break
except KeyError:
echo "Hello KeyError detected"
main()Unfortunately the fsmonitor needs an asyncdispatch implementation, it also need to gain support for Windows but that's another issue...
What you can do right now, as a workaround, is use both asyncdispatch and asyncio at the same time.
import os,osproc,fsmonitor,strutils,times
import asyncio,net
import asyncdispatch,asyncnet
var disp = newDispatcher()
var monitor = newMonitor()
let orgDir = "/home/lxuser/Dropbox/Test"
monitor.add(orgDir)
disp.register(monitor,proc (m: FSMonitor, ev: MonitorEvent) =
echo("Got event: " & $ev.kind & " at : " & $getLocalTime(getTime())))
proc main() {.async.} =
while true:
try:
if not disp.poll(1): break
await sleepAsync(1000)
except KeyError:
echo "Hello KeyError detected"
asyncCheck main()
runForever()
Something like that should work (I haven't tested it).
Error: ambiguous call; both asyncio.newDispatcher() and asyncdispatch.newDispatcher() match for: ()changing this line to avoid ambiguity :
# var disp = newDispatcher()
var disp = asyncio.newDispatcher()unfortunately results in:
lib/pure/asyncdispatch.nim(1254, 8) Error: 'cb' is not GC-safe as it accesses 'nameIterVar' which is a global using GC'ed memoryYes, you are correct --threads:on as the plan was to have some other processing done via spawn later.
With threads off the snippet compiles fine.