nim-schedules
nim-schedules copied to clipboard
Error: ambiguous call; both scheduler.newSettings
hii when i try to use nim-schedules with jester it gives the below error
code
import times, asyncdispatch, schedules
import jester
scheduler mySched:
every(seconds=1, id="sync tick"):
echo("sync tick, seconds=1 ", now())
router myRouter:
post "/api/deletedomain":
resp "test"
proc main() =
asyncCheck mySched.start()
var jester = initJester(myrouter)
jester.serve()
when isMainModule:
main()
error:
ambiguous call; both scheduler.newSettings(appName: string, errorHandler: proc (fut: Future[system.void]){.closure, gcsafe.}) [proc declared in /home/user/.nimble/pkgs/schedules-0.2.0/schedules/scheduler.nim(235, 6)] and jester.newSettings(port: Port, staticDir: string, appName: string, bindAddr: string, reusePort: bool, futureErrorHandler: proc (fut: Future[system.void]){.closure, gcsafe.}) [proc declared in /home/user/.nimble/pkgs/jester-0.5.0/jester.nim(407, 6)] match for: ()
i tried to use prologue but the mySched is never called, its not printing anything
Prologue code
import prologue
import httpclient
import schedules, times, asyncdispatch
scheduler mySched:
every(seconds=5, id="sync tick"):
echo("hello world", now())
proc hello*(ctx: Context) {.async.} =
resp "<h1>Hello, Prologue!</h1>"
proc main()=
asyncCheck mySched.start()
let app = newApp()
app.get("/", hello)
app.run()
when isMainModule:
main()
output
DEBUG Prologue is serving at http://0.0.0.0:8080
DEBUG Starting 12 threads
I think jester has introduced newSettings
since the nim-schedules doc was written. Since scheduler mySched:
implicitly requires newSettings
from nim-schedules, not one from jester, nim compiler complains.
Re Prologue, I haven't used it. I'll test it out.
I've been fighting with something like this for hours, yesterday. The initial reason being that this example is garbage.
https://github.com/soasme/nim-schedules/blob/ce1fe58ef7cc8a8670a8835031fcd5c5262083af/README.md?plain=1#L99-L124
Not even the syntax is correct; notice line 110.
So, after debugging jester
for what seemed like forever, I found the magic line that makes schedules work, even when something else is running mainly:
while true:
stderr.writeLine "Master Thread"
sleep 1_000
try:
asyncdispatch.poll(0) # Must be in a loop, every couple of seconds. Otherwise, scheduler won't work properly.
except ValueError:
continue
@d0rksh This will solve your issue with prologue
.