Add ev/to-file for synchronous resource operations#1533
Add ev/to-file for synchronous resource operations#1533bakpakin merged 7 commits intojanet-lang:masterfrom
ev/to-file for synchronous resource operations#1533Conversation
|
I think |
|
I got a tip that may be
Does that seem right? |
|
I don't think |
That is strange to me, since the windows path should be used on windows and mingw |
I don't have a MinGW environment that I can test to explore further. You can see the errors that were occurring for various approaches in my Actions history. A sample error: and if I disable buffering: I've removed the special casing in e94e8dc and, while the test suite includes a check to avoid testing in MinGW, the current commit can be experimented with in MinGW. |
|
Thanks for the work here, @pyrmont! Looks pretty solid to me, and we can investigate the mingw issue later, as I also don't have a mingw setup handy for testing right now. |
|
Great! Thanks for merging it in! I’m looking forward to using it in my project with the next Janet release :D |
This PR adds
ev/to-fileas a way to allow synchronous operations with stream-based resources (e.g. sockets).Background
Janet supports non-blocking IO operations via the
evmodule. While this is desirable in many cases, there are situations where a user wants to ensure that an operation is synchronous. Janet does not currently offer a mechanism to do this with stream-based resources (e.g. sockets).As discussed in #1531, one way to address this is is to offer a function that would create a
core/fileobject based on thecore/streamobject. Thecore/fileobject could then be used with the synchronous operations in thefilemodule.Implementation
The
src/core/ev.cfile is modified to add anev/to-filefunction. The function takes a stream object and attempts to return a file object. This can then be used in the same way as other file objects:Limitations
I wasn’t able to get this working on MinGW. Based on some cursory reading, I think this might be a limitation in how MinGW handles the use of Windows sockets via file descriptors. As a result, calling this function in a MinGW environment will raise an error.