make wait_readable and wait_writable public#8651
make wait_readable and wait_writable public#8651RX14 merged 1 commit intocrystal-lang:masterfrom stakach:patch-2
Conversation
restoring the changes made in #7366 Change was originally made in this release: https://github.com/crystal-lang/crystal/blob/3aa1a04ca666dcf12a625b58deccbf0f209e1e4d/CHANGELOG.md#0280-2019-04-17
|
Thanks @RX14 Agree that they shouldn't be used day to day but useful when doing something a little more complex that lies outside of the typical. I'd put this in a similar category to the |
|
@ysbaddaden Is there any particular reason this was reverted in #7505? |
|
Because it's internal API detail, and there aren't any need nor incentive for them to be publicly available, and nobody complained in over a year. Be aware that using this will break, most likely when adding support for Windows, or moving from libevent to a custom solution. I'd love to see a real use-case. If it's just a "feel that it should be accessible", then let's close this PR. |
|
@ysbaddaden the real usecase is binding C libraries: https://github.com/spider-gazelle/ssh2.cr/blob/a93eb957420b9e9f31bb8cd46e50ff862c5bc54b/src/session.cr#L39-L49 libgit2 returns EAGAIN from function calls when it needs to read more data, just like I suspect when we abstract the event loop, we will have Or, we could force users to use threads, which i'm not super against anyway. |
|
@RX14 ok. |
We can use IO::FileDescriptor#wait_readable (an undocumented but public method) to yield a fiber until the file descriptor has something to read. On POSIX systems (only), the X11 socket is exposed as a file descriptor. That's an acceptable limitation for now---I don't care to support X11 on Windows. crystal-lang/crystal#7366 crystal-lang/crystal#8651 https://forum.crystal-lang.org/t/fibers-blocking-io-and-c-libraries/3116/13?u=elebow
restoring the changes made in #7366
Change was originally made in this release: https://github.com/crystal-lang/crystal/blob/3aa1a04ca666dcf12a625b58deccbf0f209e1e4d/CHANGELOG.md#0280-2019-04-17