@@ -112,7 +112,7 @@ class BaseTrioEventLoop(asyncio.SelectorEventLoop):
112112 _token = None
113113
114114 # an event; set while the loop is not running
115- # To wait until the loop _is_ running, call ``await loop._sync ()``.
115+ # To wait until the loop _is_ running, call ``await loop.synchronize ()``.
116116 _stopped = None
117117
118118 # asyncio's flag whether the loop has been closed
@@ -412,10 +412,15 @@ def run_in_executor(self, executor, func, *args):
412412 assert isinstance (executor , TrioExecutor )
413413 return self .run_trio (executor .submit , func , * args )
414414
415- async def _sync (self ):
416- """Synchronize with the main loop by passing an event through it.
415+ async def synchronize (self ):
416+ """Sync with the main loop by passing an event through it.
417417
418418 This is a Trio coroutine.
419+
420+ From asyncio, call ``await trio_asyncio.run_trio(loop.synchronize)``
421+ instead of ``await asyncio.sleep(0)`` if you need to process all
422+ queued callbacks.
423+
419424 """
420425 w = trio .Event ()
421426 self ._queue_handle (w )
@@ -504,7 +509,7 @@ async def _reader_loop(self, fd, handle, task_status=trio.TASK_STATUS_IGNORED):
504509 while not handle ._cancelled : # pragma: no branch
505510 await trio .hazmat .wait_readable (fd )
506511 handle ._call_sync ()
507- await self ._sync ()
512+ await self .synchronize ()
508513 except Exception as exc :
509514 _h_raise (handle , exc )
510515 return
@@ -558,7 +563,7 @@ async def _writer_loop(self, fd, handle, task_status=trio.TASK_STATUS_IGNORED):
558563 while not handle ._cancelled : # pragma: no branch
559564 await trio .hazmat .wait_writable (fd )
560565 handle ._call_sync ()
561- await self ._sync ()
566+ await self .synchronize ()
562567 except Exception as exc :
563568 _h_raise (handle , exc )
564569 return
0 commit comments