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

Add a async interface for the Prices class #8

Merged
merged 1 commit into from
Oct 1, 2019
Merged

Add a async interface for the Prices class #8

merged 1 commit into from
Oct 1, 2019

Conversation

Hellowlol
Copy link
Contributor

Supports aiohttp, httpx and asks.

Supports aiohttp, httpx and asks.
@Hellowlol Hellowlol changed the title Add a async interfrace for the Prices class Add a async interface for the Prices class Aug 28, 2019
@kipe
Copy link
Owner

kipe commented Sep 3, 2019

Hey, thanks for this, looks good!
Could you provide an example of usage, so I could better evaluate this. This is especially important, as I'm not good with async programming myself 😄

@Hellowlol
Copy link
Contributor Author

Hellowlol commented Sep 3, 2019

No problem, see the example below

import curio
import asyncio

async def test_ask():
    import asks
    asks.init('curio')
    client = asks.Session()
    Prices = AioPrices("NOR", client)
    result = await prices.hourly()
    print(result)


No problem :)

async def test_aiohttp():
    import aiohttp
    client = aiohttp.ClientSession()
    Prices = AioPrices("NOR", client)
    result = await prices.hourly()
    print(result)



async def test_httpx():
    import httpx
    client = httpx.AsyncClient()
    Prices = AioPrices("NOR", client)
    result = await prices.hourly()
    print(result)

asyncio.run(test_httpx())
#asyncio.run(test_aiohttp())
# curio.run(test_ask)

aiohttp might give you warning because of unclosed session. This is intended as async usually is used in larger projects and we want to use the same "client" as much as possible. The user need do thencleanup them selves.

@kipe
Copy link
Owner

kipe commented Oct 1, 2019

Hey, sorry this took so long, I just forgot!
Looks good, thank you 👍

@kipe kipe merged commit 405d81a into kipe:master Oct 1, 2019
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

Successfully merging this pull request may close these issues.

2 participants