I'm not sure if aiofiles is stable or not, but I would like the actual implementation to be slightly different. aiofiles simply proxies all file IO operations through a thread pool, but there are better alternatives in some cases. Using a thread pool is totally fine for vanilla asyncio, but there should be a way for projects like uvloop/twisted to inject their own implementation of asynchronous file IO.
To do that we probably need to define an abstract file IO interface and add a method to event loop to return an object that implements that interface. For instance:
# in asyncio:
class asyncio.AbstractFileIOImplementation:
async def open(self):
raise NotImplementedError
async def open(...):
return await get_current_loop(). get_file_io_implementation().open(...)
# in uvloop or twisted or ...:
class uvloop.FileIO(asyncio.AbstractFileIOImplementation):
# ... implementation of "open()"
class uvloop.Loop:
def get_file_io_implementation(self):
return self
# later in user code:
async def main():
file = await asyncio.open(...)