awesome-asyncio icon indicating copy to clipboard operation
awesome-asyncio copied to clipboard

Add async_property

Open ryananguiano opened this issue 6 years ago • 2 comments

What is this project?

You can use @async_property just as you would with @property, but on an async function.

class Foo:
    @async_property
    async def remote_value(self):
        return await get_remote_value()

The property remote_value now returns an awaitable coroutine.

instance = Foo()
await instance.remote_value

Why is it awesome?

  • Both regular and cached property.
  • Cached properties can be accessed multiple times without repeating function.
  • Cus duh!

ryananguiano avatar Apr 11 '19 20:04 ryananguiano

Forgot the link: https://github.com/ryananguiano/async_property

ryananguiano avatar Apr 11 '19 20:04 ryananguiano

Ready for merge

ryananguiano avatar Mar 04 '22 20:03 ryananguiano