Skip to content

Commit 4ef8b05

Browse files
committed
promote loop._sync to a public interface: loop.syncronize
TODO: think of a sensible name for calling this from asyncio.
1 parent 065eba5 commit 4ef8b05

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

trio_asyncio/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# This file is imported from __init__.py and exec'd from setup.py
22

3-
__version__ = "0.5.0"
3+
__version__ = "0.6.0"

trio_asyncio/base.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)