| 103 | release = anyio.Event() |
| 104 | |
| 105 | async def hook(_path: str) -> None: |
| 106 | nonlocal in_flight, peak |
| 107 | in_flight += 1 |
| 108 | peak = max(peak, in_flight) |
| 109 | try: |
| 110 | if in_flight == 2 and not release.is_set(): |
| 111 | # Hold both a little longer so a flush that ignored the bound |
| 112 | # would have time to start a third upload before they leave. |
| 113 | await anyio.sleep(0.1) |
| 114 | release.set() |
| 115 | with anyio.fail_after(5): |
| 116 | await release.wait() |
| 117 | finally: |
| 118 | in_flight -= 1 |
| 119 | |
| 120 | server.upload_hook = hook |
| 121 | await stores.flush_writes() |