Context
Adapter
Bases: typing.Protocol[T]
is_closed(client)
Returns whether the client state is closed or released.
new()
Creates a new client.
release(client)
Closes or releases the client.
AsyncAdapter
Bases: typing.Protocol[T]
Represents an Adapter to a Specific Service.
is_closed(client)
async
Returns whether the client state is closed or released.
new()
async
Creates a new client.
release(client)
async
Closes or releases the client.
AtomicAdapter
Bases: Adapter[T]
, typing.Protocol[T]
Represents an Adapter to a Specific Service that can perform atomic operations.
begin(client)
Starts an atomic operation.
commit(client)
Commits an atomic operation.
in_atomic(client)
Returns whether the client is currently in an atomic operation.
rollback(client)
Rolls back an atomic operation.
AtomicAsyncAdapter
Bases: AsyncAdapter[T]
, typing.Protocol[T]
Represents an Adapter to a Specific Service that can perform atomic operations.
begin(client)
async
Starts an atomic operation.
commit(client)
async
Commits an atomic operation.
in_atomic(client)
async
Returns whether the client is currently in an atomic operation.
rollback(client)
async
Rolls back an atomic operation.
Context
Bases: typing.Generic[T]
adapter: interfaces.Adapter[T]
property
Returns the adapter that is being used by this context.
stack: int
property
Returns how many frames are using this context.
__enter__()
Acquires a new resource from the adapter and increases the stack count.
__exit__(*_)
Releases the current resource if the stack count is 1, and decreases the stack count.
__init__(adapter)
Initialize a new Context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adapter |
interfaces.Adapter[T]
|
An adapter that will be used to acquire and release resources. |
required |
acquire()
Acquires a new resource from the adapter and increases the stack count.
begin()
A context manager that acquires and releases resources and returns it.
client()
Returns the current resource being used by the context. Acquires a new resource if the current one is closed or doesn't exist.
is_active()
Returns whether the context is currently in use.
open()
A context manager that acquires and releases resources without returning it.
release()
Releases the current resource if the stack count is 1, and decreases the stack count.
AsyncContext
Bases: typing.Generic[T]
adapter: interfaces.AsyncAdapter[T]
property
Returns the adapter that is being used by this context.
stack: int
property
Returns how many frames are using this context.
__aenter__()
async
Acquires a new resource from the adapter and increases the stack count.
__aexit__(*_)
async
Releases the current resource if the stack count is 1, and decreases the stack count.
__init__(adapter)
Initialize a new AsyncContext.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adapter |
interfaces.AsyncAdapter[T]
|
An async adapter that will be used to acquire and release resources. |
required |
acquire()
async
Acquires a new resource from the adapter and increases the stack count.
begin()
async
An async context manager that acquires and releases resources and returns it.
client()
async
Returns the current resource being used by the context. Acquires a new resource if the current one is closed or doesn't exist.
is_active()
Returns whether the context is currently in use.
open()
async
An async context manager that acquires and releases resources without returning it.
release()
async
Releases the current resource if the stack count is 1, and decreases the stack count.
atomic(context, bound=True)
Create an atomic context or a bound context based on the given context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
Union[Context[T], AsyncContext[T]]
|
The base context to be wrapped. |
required |
bound |
bool
|
Whether to create a bound context. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Union[Context[T], AsyncContext[T]]
|
Union[Context[T], AsyncContext[T]]: The created atomic or bound context. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provider received is not compliant with the atomic adapter interface. |