🔍 Code Extractor

function async_action

Maturity: 43

A decorator function that marks another function as asynchronous by adding an 'is_async' attribute, while preserving the original function's metadata.

File:
/tf/active/vicechatdev/CDocs/controllers/__init__.py
Lines:
170 - 179
Complexity:
simple

Purpose

This decorator is designed to tag action functions as asynchronous for future implementation of async functionality. Currently acts as a pass-through decorator that adds metadata (is_async=True) to the wrapped function without changing its behavior. It's intended for use in a system where actions need to be identified as async for routing, scheduling, or execution purposes.

Source Code

def async_action(func):
    """
    Decorator to mark action as asynchronous.
    This is a placeholder for future implementation.
    """
    @wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)
    wrapper.is_async = True
    return wrapper

Parameters

Name Type Default Kind
func - - positional_or_keyword

Parameter Details

func: The function to be decorated. Can be any callable (function or method) that will be marked as asynchronous. No constraints on the function signature - it accepts any parameters and return type.

Return Value

Returns a wrapper function that behaves identically to the input function but has an additional attribute 'is_async' set to True. The wrapper preserves the original function's name, docstring, and other metadata via functools.wraps. The return type matches whatever the decorated function returns.

Dependencies

  • functools

Required Imports

from functools import wraps

Usage Example

from functools import wraps

def async_action(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)
    wrapper.is_async = True
    return wrapper

# Example usage
@async_action
def process_document(doc_id, user_id):
    """Process a document asynchronously."""
    print(f"Processing document {doc_id} for user {user_id}")
    return {"status": "processed", "doc_id": doc_id}

# Check if function is marked as async
print(process_document.is_async)  # Output: True

# Call the function normally
result = process_document(123, 456)
print(result)  # Output: {'status': 'processed', 'doc_id': 123}

Best Practices

  • This is a placeholder decorator - the actual async behavior is not implemented yet, so decorated functions will still execute synchronously
  • Use this decorator to mark functions that should be executed asynchronously in future implementations
  • Check for the 'is_async' attribute on functions to determine if they should be handled asynchronously: hasattr(func, 'is_async') and func.is_async
  • The decorator preserves function metadata using @wraps, so introspection tools will work correctly
  • Can be stacked with other decorators, but order may matter depending on what other decorators do
  • Since this is a placeholder, ensure your codebase has a plan for implementing actual async execution when needed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function log_controller_action 50.5% similar

    A decorator factory that logs controller actions with different log levels based on whether the action is routine or non-routine, and handles exceptions during execution.

    From: /tf/active/vicechatdev/CDocs/controllers/__init__.py
  • function async_execute 50.3% similar

    Wraps and schedules async function execution in the appropriate event loop context, ensuring proper lock propagation and document context management for Bokeh/Panel applications.

    From: /tf/active/vicechatdev/patches/server.py
  • function transaction 49.1% similar

    A decorator function that wraps another function to provide database transaction management capabilities, currently implemented as a placeholder for future transaction handling.

    From: /tf/active/vicechatdev/CDocs/controllers/__init__.py
  • function run_analysis_async 42.7% similar

    Executes a data analysis workflow asynchronously with real-time progress tracking, including query interpretation, script generation, execution, and result finalization.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function require_auth 42.1% similar

    A decorator function that enforces authentication requirements on Flask route handlers by checking if a user is authenticated before allowing access to the decorated function.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
← Back to Browse