Skip to content

A small python package for using asynchronous code from synchronous code.

License

Notifications You must be signed in to change notification settings

xloem/async_to_sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async_to_sync

Convert async coroutine functions to normal ones.

Installation

$ pip install async_to_sync

Usage

import async_to_sync as sync

# an async object method to demonstrate use
class async_class:
    async def sum(self, a, b):
        return a + b
async_object = async_class()

# wrap all async methods of an object
sync_object = sync.methods(async_object)

assert sync_object.sum(1,2) == 3

# wrap a single async callable
sync_function = sync.function(async_object.sum)

assert sync_function(4,5) == 9

# wait for a coroutine
sync_result = sync.coroutine(async_object.sum(6,7))

assert sync_result == 13

# manually stop default event loop
sync.stop()

# manually start default event loop
sync.start()

About

A small python package for using asynchronous code from synchronous code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages