Append or enqueue a markdown fragment. Args: markdown_fragment: A string to append at the end of the document.
(self, markdown_fragment: str)
| 76 | self._stopped = True |
| 77 | |
| 78 | async def write(self, markdown_fragment: str) -> None: |
| 79 | """Append or enqueue a markdown fragment. |
| 80 | |
| 81 | Args: |
| 82 | markdown_fragment: A string to append at the end of the document. |
| 83 | """ |
| 84 | if self._stopped: |
| 85 | raise RuntimeError("Can't write to the stream after it has stopped.") |
| 86 | if not markdown_fragment: |
| 87 | # Nothing to do for empty strings. |
| 88 | return |
| 89 | # Append the new fragment, and set an event to tell the _run loop to wake up |
| 90 | self._pending.append(markdown_fragment) |
| 91 | self._new_markup.set() |
| 92 | # Allow the task to wake up and actually display the new markdown |
| 93 | await asyncio.sleep(0) |
| 94 | |
| 95 | async def _run(self) -> None: |
| 96 | """Run a task to append markdown fragments when available.""" |