dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.4k stars 10k forks source link

Async IPooledObjectPolicy<T> #53512

Open kijanawoodard opened 9 months ago

kijanawoodard commented 9 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I'm trying to create an IPooledObjectPolicy where IBrowser is from Playwright.net. However, Playwright's method to create an IBroswer is LaunchBrowserAsync.

Describe the solution you'd like

An async ObjectPool stack would be nice.

I'm guessing the viral nature of async makes this a more complex feature request?

Additional context

No response

amcasey commented 8 months ago

That's an interesting idea and I don't see any obvious reason why it wouldn't work, but I also can't recall having heard a request for that before.

Are there other async-factory types you need to pool or is it just IBrowser? If it's just browsers, do you need a scalable number of instances or can you just pre-allocate the number you require and then consume them from a simpler collection, like a list?

kijanawoodard commented 8 months ago

I don't have another case off the top of my head, but "everything's async now".

I was about to criticize another dev for not using the object pool, but decided to just take a crack at it myself. Ran square into this issue.

I ended up building a custom pool + pool policy. I skipped the pool provider. It's not awful, but it would have been nice to be able to use the bcl pool.

amcasey commented 8 months ago

One of the few exceptions to the "everything's async" heuristic is object initialization, which remains stubbornly synchronous. For pool rental to be substitutable for new, it has to be synchronous too.

Let's keep this around and see if any other use cases arise.

ghost commented 8 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

noldoreldar commented 1 month ago

I also strongly agree with this idea. I heavily use object pools for many different scenarios. And some of these classes (if not most) need async initialization after constructing a new instance. Even some don't have a constructor, yet a static async Create factory method. Such as the given example here Playwright's Browser initialization. Or ConnectionMultiplexer of Redis.. It's another discussion topic if these classes really need to be pooled or not. It doesn't change the fact there is always a use case.