RafaelWO / unparallel

Create async web requests via Python in no time.
https://rafaelwo.github.io/unparallel/
MIT License
10 stars 0 forks source link

Feature: Add parameter to configure custom response function #109

Closed RafaelWO closed 8 months ago

RafaelWO commented 10 months ago

Description

This PR adds the feature of defining custom response functions to process the response, i.e. callbacks. This means that the user can decide what to do with the response.

A simple example might be getting the HTTP status codes for a bunch of URLs:

import asyncio

from unparallel import up

async def main():
    urls = [
        "https://www.example.com",
        "https://duckduckgo.com/",
        "https://github.com"
    ]
    return await up(urls, method="HEAD", response_fn=lambda x: x.status_code)

results = asyncio.run(main())
print(results)

This prints:

Making async requests: 100%|███████████| 3/3 [00:00<00:00,  4.43it/s]
[200, 200, 200]

Main Changes:

Additional Changes:

Related Issue

Closes #100

Type of Change

Checklist