Skip to content

inyutin/asyncio_guard

Repository files navigation

Guard that provide exclusive access to an object

Python 3.7 or higher.

Install: pip install asyncio-guard

"Buy Me A Coffee"

Examples of usage:

  1. Set a value, get exclusive access to it, set another value
guard = Guard(obj=1)

async with guard as obj:
    assert obj == 1

await guard.set(2)
async with guard as obj:
    assert obj == 2
  1. Update a value by using update function.
    This update function will be used, if no value was set up.
guard = Guard(obj=1, update_func=lambda: return 2)

async with guard as obj:
    assert obj == 1

await guard.update_func()
async with guard as obj:
    assert obj == 2

About

Guard that provide exclusive access to an object

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages