AsyncBackendMixin
Mixin for backends that enables the async API.
Attributes
| Attribute | Type | Description |
|---|---|---|
| result_consumer | [ResultConsumer](../rpc/resultconsumer.md?sid=celery_backends_rpc_resultconsumer) | The consumer instance responsible for managing result buckets, drainers, and message consumption for asynchronous tasks. |
| _pending_messages | MessageBuffer | A buffer containing messages that have been received but not yet processed or resolved into result objects. |
| _pending_results | tuple | A tuple containing two mappings (concrete and weak) used to track active task IDs and their corresponding result objects. |
| is_async | boolean = True | A read-only flag indicating that the backend supports the asynchronous API. |
Methods
iter_native()
@classmethod
def iter_native(
result: [ResultSet](../../result/resultset.md?sid=celery_result_resultset),
no_ack: boolean = True
) - > generator
Iterates over results as they become available from the native backend, yielding task IDs and their associated data.
Parameters
| Name | Type | Description |
|---|---|---|
| result | [ResultSet](../../result/resultset.md?sid=celery_result_resultset) | The set of results to iterate over and monitor for completion |
| no_ack | boolean = True | Whether to disable manual acknowledgment of messages from the underlying transport |
Returns
| Type | Description |
|---|---|
generator | A generator yielding tuples of (task_id, result_data) for each completed task |
add_pending_result()
@classmethod
def add_pending_result(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult),
weak: boolean = False,
start_drainer: boolean = True
) - > [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)
Adds a result to the tracking system and initiates the background drainer to start listening for its completion.
Parameters
| Name | Type | Description |
|---|---|---|
| result | [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult) | The result object to begin tracking for asynchronous updates |
| weak | boolean = False | If true, the result is stored using a weak reference to allow for earlier garbage collection |
| start_drainer | boolean = True | Whether to immediately start the result consumer's background event loop |
Returns
| Type | Description |
|---|---|
[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult) | The result object that was added to the pending tracking system |
add_pending_results()
@classmethod
def add_pending_results(
results: list,
weak: boolean = False
) - > list
Registers multiple result objects for tracking and ensures the result consumer drainer is active.
Parameters
| Name | Type | Description |
|---|---|---|
| results | list | A collection of AsyncResult objects to be tracked asynchronously |
| weak | boolean = False | If true, all results in the list will be stored as weak references |
Returns
| Type | Description |
|---|---|
list | A list of the AsyncResult objects that were added to the tracking system |
remove_pending_result()
@classmethod
def remove_pending_result(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)
) - > [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)
Removes a result from the pending tracking system and performs cleanup actions once the result is fulfilled.
Parameters
| Name | Type | Description |
|---|---|---|
| result | [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult) | The result object to stop tracking |
Returns
| Type | Description |
|---|---|
[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult) | The result object that was removed from tracking |
on_result_fulfilled()
@classmethod
def on_result_fulfilled(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)
) - > null
Handles cleanup for a fulfilled result by canceling any active subscriptions for its task ID in the consumer.
Parameters
| Name | Type | Description |
|---|---|---|
| result | [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult) | The result object that has been successfully resolved |
Returns
| Type | Description |
|---|---|
null |
wait_for_pending()
@classmethod
def wait_for_pending(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult),
callback: callable = null,
propagate: boolean = True
) - > object
Blocks until the specified result is ready, optionally propagating exceptions or executing a callback upon completion.
Parameters
| Name | Type | Description |
|---|---|---|
| result | [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult) | The result object to wait for |
| callback | callable = null | An optional function to execute once the result is ready |
| propagate | boolean = True | Whether to raise the task's exception if the task failed |
Returns
| Type | Description |
|---|---|
object | The resolved value of the result, or raises an exception if propagate is True |
is_async()
@classmethod
def is_async() - > boolean
Indicates whether the backend supports asynchronous operations.
Returns
| Type | Description |
|---|---|
boolean | Always returns True for this mixin |