privex.helpers.asyncx

Functions and classes related to working with Python’s native asyncio support

To avoid issues with the async keyword, this file is named asyncx instead of async

Copyright:

    +===================================================+
    |                 © 2019 Privex Inc.                |
    |               https://www.privex.io               |
    +===================================================+
    |                                                   |
    |        Originally Developed by Privex Inc.        |
    |        License: X11 / MIT                         |
    |                                                   |
    |        Core Developer(s):                         |
    |                                                   |
    |          (+)  Chris (@someguy123) [Privex]        |
    |          (+)  Kale (@kryogenic) [Privex]          |
    |                                                   |
    +===================================================+

Copyright 2019     Privex Inc.   ( https://www.privex.io )

Attributes

Functions

async_sync(f)

Async Synchronous Decorator, borrowed from https://stackoverflow.com/a/23036785/2648583 - added this PyDoc comment and support for returning data from a synchronous function

await_if_needed(func, *args, **kwargs)

Call, await, and/or simply return func depending on whether it’s an async function reference (coroutine function), a non-awaited coroutine, a standard synchronous function, or just a plain old string.

awaitable(func)

Decorator which helps with creation of async wrapper functions.

awaitable_class(cls)

Wraps a class, allowing all async methods to be used in non-async code as if they were normal synchronous methods.

call_sys_async(proc, *args[, write])

Async version of call_sys() - works exactly the same, other than needing to be await’d.

get_async_type(obj)

Detects if obj is an async object/function that needs awaited / called, whether it’s a synchronous callable, or whether it’s unknown (probably not async)

is_async_context()

Returns True if currently in an async context, otherwise False

loop_run(coro, *args[, _loop])

Run the coroutine or async function coro synchronously, using an AsyncIO event loop.

run_sync(func, *args, **kwargs)

Run an async function synchronously (useful for REPL testing async functions).

Classes

AwaitableMixin()

aobject(*a, **kw)

Inheriting this class allows you to define an async __init__.