Skip to content

Conversation

yglukhov
Copy link
Member

This pr allows using asyndispatch in any thread of a conventional MacOS/iOS app, including the main thread.
Notes:

  • Upon newDispatcher creation it's kqueue is added to current CFRunLoop. This only happens if the program was linked with CoreFoundation in the first place.
  • Any event in this kqueue will trigger poll(0) to dispatch them.
  • There's no performance hit for existing code using asyncdispatch.
  • sleepAsync is not supported properly yet and may be laggy when CFRunLoop is used.

In future I'm planning to do the same for Android.

# MacOS has CFRunloop API, used in most of MacOS apps. This code allows
# nim asyncdispatch to interoperate with existing CFRunloop.

# This module is included by asyncdispatch, and relies on `pool` function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight spelling change:

and relies on poll function

@dom96
Copy link
Contributor

dom96 commented Apr 16, 2018

What's the rationale for putting this in the stdlib?

@yglukhov
Copy link
Member Author

@dom96, the rationale is seamless macos support out of the box? I could start with a separate lib for now (given that we still expose some currently private fields), but that would still have implications that the user has to manually call some initializer code on every thread he wants to mix async and CFRunloop.

But isn't "seamless" macos support a good enough argument already? Or is there anything that bothers you about the impl?

@Araq
Copy link
Member

Araq commented Apr 16, 2018

I think it's cool.

@dom96
Copy link
Contributor

dom96 commented Apr 16, 2018

What bothers me is that it's another bit of code that needs to be maintained and that I need to worry about as a potential cause of async issues. Nothing in the stdlib depends on it, so I don't see why it should be included. Sorry, but I think it can just as easily be a Nimble package.

@Araq
Copy link
Member

Araq commented Apr 16, 2018

How about we accept the changes that export the fields that make a nimble package easier to build against async?

@dom96
Copy link
Contributor

dom96 commented Apr 16, 2018 via email

@yglukhov
Copy link
Member Author

Makes sense. Closing.

@yglukhov yglukhov closed this Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants