UniCoreFW

defer()

Defer invoking the function until the current call stack has cleared.

Implementation

Args: func: The function to defer *args: Arguments to pass to the function **kwargs: Keyword arguments to pass to the function Returns: None

Example

def add(x, y): return x + y defer(add, 1, 2) 3

Expected output: Prints 'Deferred' after current execution completes

Source Code

def defer(func: Callable, *args, **kwargs) -> None: threading.Timer(0, func, args=args, kwargs=kwargs).start()