nim-schedules icon indicating copy to clipboard operation
nim-schedules copied to clipboard

Error: ambiguous call; both scheduler.newSettings

Open d0rksh opened this issue 1 year ago • 3 comments

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: ()

d0rksh avatar Aug 18 '22 13:08 d0rksh

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

d0rksh avatar Aug 19 '22 07:08 d0rksh

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.

soasme avatar Aug 19 '22 23:08 soasme

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.

theAkito avatar Oct 23 '22 17:10 theAkito