Skip to content
Advertisement

Separating async requests and saving using aiohttp

I am currently calling an external API many times and downloading the response’s content from each call. I am using aiohttp and asyncio to speed up this process, but am having trouble figuring out how to separate the fetch functionality from the save functionality.

Setup

JavaScript

Currently, I am using the following function:

JavaScript

My main call looks like this:

JavaScript

Given this basic example, is it possible to separate the fetch and save functionality in fetch_and_save?

Advertisement

Answer

Just create independent functions for fetch portion and save portion.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement