Skip to content

Instantly share code, notes, and snippets.

@crclz
Created Aug 23, 2021
Embed
What would you like to do?

python:

import aiohttp
import asyncio

async def main():
    async with aiohttp.ClientSession() as session:
        pokemon_url = 'https://pokeapi.co/api/v2/pokemon/151'
        async with session.get(pokemon_url) as resp:
            pokemon = await resp.json()
            print(pokemon['name'])

asyncio.run(main())

c#: (async/await)始祖

using aiohttp
using asyncio

async void main(){
    await using (var session = aiohttp.ClientSession()) {
        var pokemon_url = 'https://pokeapi.co/api/v2/pokemon/151'
        await using (var resp = await session.get(pokemon_url)) {
            pokemon = await resp.json()
            print(pokemon['name'])
        }
    }
}

Task.start(()=> main() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment