Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setGlobalDispatcher should be initGlobalDispatcher...? #11584

Open
sinkingsugar opened this issue Jun 25, 2019 · 0 comments
Open

setGlobalDispatcher should be initGlobalDispatcher...? #11584

sinkingsugar opened this issue Jun 25, 2019 · 0 comments
Labels

Comments

@sinkingsugar
Copy link
Contributor

I'm having to consume a module that uses asyncdispatch and I'm scratching my head to make it work properly in my fibers/coroutine heavy setup.
I decided to let each coroutine to have it's own dispatcher but sadly I discovered that it's not possible at all due to setGlobalDispatcher being initGlobalDispatcher
This is the proc...

proc setGlobalDispatcher*(disp: PDispatcher) =
  if not gDisp.isNil:
    assert gDisp.callbacks.len == 0
  gDisp = disp
  initCallSoonProc()

As you can see it supposedly should set the global dispatcher.. but in the process it asserts that it's empty and initializes it basically.
This makes it impossible to have something like withDispatcher mydispatcher for example
where the template would be:

template withDispatcher*(disp: PDispatcher; body: untyped): untyped =
  let currentDispatcher = getGlobalDispatcher()
  setGlobalDispatcher(disp)
  body
  setGlobalDispatcher(currentDispatcher)

To me this makes no sense and both get and init are probably needed.
Currently it's very misleading.

@Araq Araq added the Feature label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants