Open clemlesne opened 1 month ago
i think this is a really good idea. in 0.6.0 we replaced the property
-based cached var with our own custom descriptor, so it should theoretically be possible to implement this now, but some parts may not work properly; for example if i access an async property via getattr
from a non-async function, what should happen?
Well good question.
From a developer point of view, it could return the expected value or None
(not loaded).
But how to know if the cached var is None
or if it is not loaded? We could implement an object with a loaded
state and a return value (default to None
); maybe overkill.
Motivations
loaded
state asbool
to be alerted of the loading stateif/else
in the UI to wait for the data to be loadedExample of expected usage
Implementation
Under the hood, this could be achieved with a background task loading the data, the cached var returning
None
until it is loaded.Or, the async task can be wrapped by asyncio to be called synchronously from the app:
asyncio.get_event_loop().run_until_complete(func(...))
.