Skip to content

Instantly share code, notes, and snippets.

@crclz
Created August 23, 2021 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crclz/2308cc72cc3f37836a6cab22c1981849 to your computer and use it in GitHub Desktop.
Save crclz/2308cc72cc3f37836a6cab22c1981849 to your computer and use it in GitHub Desktop.

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