diff --git a/subiquitycore/async_helpers.py b/subiquitycore/async_helpers.py index a126af76..fdcc6ad8 100644 --- a/subiquitycore/async_helpers.py +++ b/subiquitycore/async_helpers.py @@ -113,3 +113,8 @@ class SingleInstanceTask: return await self.task except asyncio.CancelledError: pass + + def done(self): + if self.task is None: + return False + return self.task.done() diff --git a/subiquitycore/tests/test_async_helpers.py b/subiquitycore/tests/test_async_helpers.py index 835cbae0..392d6954 100644 --- a/subiquitycore/tests/test_async_helpers.py +++ b/subiquitycore/tests/test_async_helpers.py @@ -56,10 +56,13 @@ class TestSITWait(unittest.IsolatedAsyncioTestCase): sit = SingleInstanceTask(fn) await sit.start() await asyncio.wait_for(sit.wait(), timeout=1.0) + self.assertTrue(sit.done()) async def test_wait_not_started(self): async def fn(): self.fail('not supposed to be called') sit = SingleInstanceTask(fn) + self.assertFalse(sit.done()) with self.assertRaises(asyncio.TimeoutError): await asyncio.wait_for(sit.wait(), timeout=0.1) + self.assertFalse(sit.done())