from unsync import unsync
import asyncio
import datetime
import math
import aiohttp
import requests


def main():
    t0 = datetime.datetime.now()
    tasks = [
        compute_some(),
        compute_some(),
        compute_some(),
        download_some(),
        download_some(),
        download_some(),
        download_some_more(),
        download_some_more(),
        wait_some(),
        wait_some(),
        wait_some(),
        wait_some()]

    [t.result() for t in tasks]
    dt = datetime.datetime.now() - t0
    print('Unsync version done in {:,.2f} seconds.'.format(dt.total_seconds()))


@unsync(cpu_bound=True)
def compute_some():
    print('Computing...')
    for _ in range(1, 10_000_000):
        math.sqrt(25 ** 25 + .01)


@unsync()
async def download_some():
    print('Downloading...')
    url = 'https://talkpython.fm/episodes/show/174/coming-into-python-from-another-industry-part-2'
    async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
        async with session.get(url) as resp:
            resp.raise_for_status()
            text = await resp.text()
            print('Downloaded (more) {:,} characters'.format(len(text)))


@unsync()
def download_some_more():
    print('Downloading more...')
    url = 'https://pythonbytes.fm./episodes/show/92/will-your-python-be-compiled'
    resp = requests.get(url)
    resp.raise_for_status()
    text = resp.text
    print('Downloaded (more) {:,} characters'.format(len(text)))


@unsync()
async def wait_some():
    print('Waiting...')
    for _ in range(1, 1000):
        await asyncio.sleep(.001)


if __name__ == '__main__':
    main()

[((30, 1, 30, 23), 'unsync.unsync', 'unsync', (), '', False, 'from unsync import unsync\n'), ((37, 1, 37, 9), 'unsync.unsync', 'unsync', ({}, {}), '()', False, 'from unsync import unsync\n'), ((48, 1, 48, 9), 'unsync.unsync', 'unsync', ({}, {}), '()', False, 'from unsync import unsync\n'), ((58, 1, 58, 9), 'unsync.unsync', 'unsync', ({}, {}), '()', False, 'from unsync import unsync\n'), ((10, 9, 10, 32), 'datetime.datetime.now', 'datetime.datetime.now', ({}, {}), '()', False, 'import datetime\n'), ((52, 11, 52, 28), 'requests.get', 'requests.get', ({(52, 24, 52, 27): 'url'}, {}), '(url)', False, 'import requests\n'), ((26, 9, 26, 32), 'datetime.datetime.now', 'datetime.datetime.now', ({}, {}), '()', False, 'import datetime\n'), ((34, 8, 34, 33), 'math.sqrt', 'math.sqrt', ({(34, 18, 34, 32): '(25 ** 25 + 0.01)'}, {}), '(25 ** 25 + 0.01)', False, 'import math\n'), ((62, 14, 62, 33), 'asyncio.sleep', 'asyncio.sleep', ({(62, 28, 62, 32): '(0.001)'}, {}), '(0.001)', False, 'import asyncio\n'), ((41, 47, 41, 78), 'aiohttp.TCPConnector', 'aiohttp.TCPConnector', (), '', False, 'import aiohttp\n')]