Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def results(self, tids: Sequence[TaskID]) -> Sequence[R]:
"""Wait for all tasks to complete, and return results, preserving order."""
pending = set(tids)
ready: Dict[TaskID, R] = {}
while pending:
for tid in pending.copy():
if tid in self._results:
result, tb = self._results.pop(tid)
if tb is not None:
raise ProxyException(tb)
ready[tid] = result
pending.remove(tid)
await asyncio.sleep(0.005)
return [ready[tid] for tid in tids]