aclosing_iterator_wrapper
Wraps an asynchronous iterable to ensure a provided close callback is executed upon completion or failure, while temporarily disconnecting and reconnecting the Django request_finished signal to manage database connection cleanup.
def aclosing_iterator_wrapper(
iterable: AsyncIterable,
close: Callable
) - > AsyncIterator
Wraps an asynchronous iterable to ensure a cleanup callback is executed after iteration completes or an error occurs. It manages the Django request_finished signal connection to prevent premature connection closing during the cleanup process.
Parameters
| Name | Type | Description |
|---|---|---|
| iterable | AsyncIterable | The source asynchronous iterable to be consumed and yielded. |
| close | Callable | A cleanup function invoked in the finally block to release resources or close connections. |
Returns
| Type | Description |
|---|---|
AsyncIterator | An asynchronous generator that yields chunks from the original iterable. |