Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"yield from" still exists #5

Closed
franckinux opened this issue Jun 1, 2017 · 5 comments
Closed

"yield from" still exists #5

franckinux opened this issue Jun 1, 2017 · 5 comments

Comments

@franckinux
Copy link

Since you've adopted the "async def" syntax, it would be coherent to use the "await" syntax.
"yield from" syntax can is present in the file helpers.py

@zzzsochi
Copy link
Owner

zzzsochi commented Jun 4, 2017

Yes. I'll rewrite it later.
Or make me a PR. :-)

@varac
Copy link

varac commented Oct 27, 2018

Also, providing an example using asyncio.run() would be helpful.

@zzzsochi
Copy link
Owner

asyncio.run? It's strange. This is library, not a full program. In example from readme, you can use some about this:

asyncio.run(asyncio.wait([nexter(mpc), volumer(mpc)]))

@varac
Copy link

varac commented Oct 29, 2018

@zzzsochi Thx. Here's the example from the README.md without any yield from and with asyncio.run() (imo much better readable) - although it requires python 3.7:

#!/usr/bin/env python3.7
# -*- coding: utf-8 -*-

import asyncio
import aiompd

URLS = [
    "http://stream.fsk-hh.org:8000/fsk.mp3",
    "http://streaming.fueralle.org:8000/corax.mp3"
]
PLAY_TIME = 15


async def nexter(mpc):
    await mpc.clear()

    for url in URLS:
        await mpc.add(url)

    for n in range(len(URLS)):
        print("Playing track", n)
        await mpc.play(track=n)
        await asyncio.sleep(PLAY_TIME)


async def volumer(mpc):
    timeout = (len(URLS) * PLAY_TIME) / 200

    for volume in range(0, 101, 1):
        await mpc.set_volume(volume)
        await asyncio.sleep(timeout)

    for volume in range(100, -1, -1):
        await mpc.set_volume(volume)
        await asyncio.sleep(timeout)


async def main():
    mpc = await aiompd.Client.make_connection()
    tasks = [nexter(mpc), volumer(mpc)]
    await asyncio.gather(*tasks)

asyncio.run(main())

@zzzsochi
Copy link
Owner

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants