aiometer icon indicating copy to clipboard operation
aiometer copied to clipboard

`gather` drop-in replacement

Open prophile opened this issue 2 years ago • 3 comments
trafficstars

Hello!

asyncio's own gather is a bit of a dated design but still pretty common, at least in codebases I'm dealing with at the moment—converting them to amap would be nice but it would also be dead useful to be able to drop-in replace with an aiometer.gather in a like-for-like fashion to add metering separately.

It's not impossible to shim on top of amap but would it be something you'd consider bringing into scope in the library itself? Especially since the exception handling semantics of gather can be a bit subtle.

prophile avatar Aug 25 '23 14:08 prophile

Hi @prophile

This is interesting at first, but I’m not sure.

Like you said, gather has its own quirks. For example, I believe it’s possible to pass a flag that changes its behavior quite substantially.

The library already has run_all and run_any helpers which build on top of amap. Don’t those do the trick?

florimondmanca avatar Aug 25 '23 15:08 florimondmanca

Potentially yes, and switching over to them would be an aspiration. But changing something from using asyncio.gather to aiometer.run_all isn't necessarily drop-in in the sense that things might rely on asyncio.gather's peculiarities and changing them might cause a breakage.

For me (us) I think that's useful to do, but it would also be useful to get metering in the short term before doing the bigger job of changing over to run_all.

prophile avatar Aug 25 '23 16:08 prophile

I think I understand where you’re at, but let me rephrase this.

What piece of public API do you think we could add to aiometer that would address this use case? If we were to add a gather « like for like but with metering », what would be its signature and a few code usage examples?

florimondmanca avatar Aug 26 '23 07:08 florimondmanca