79605510

Date: 2025-05-04 10:20:23
Score: 2.5
Natty:
Report link

No one mentions this simple solution ?

class MyClass:

    def __init__(self):
        self._is_ready = asyncio.Event()
        asyncio.create_task(self._init_async())

    async def _init_async(self):
        await something_eventually()
        
        # set your event
        self._is_ready.set()

    async def my_method(self):

        # wait for the event
        await self._is_ready.wait()
        
        print("now the _init_async is done")
Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Guillaume Patin