oatpp-postgresql icon indicating copy to clipboard operation
oatpp-postgresql copied to clipboard

Is it possible to use dbClient non-blocking with coroutines and async controllers?

Open MikhailNazarov opened this issue 4 years ago • 4 comments

MikhailNazarov avatar Dec 03 '21 13:12 MikhailNazarov

Hello @MikhailNazarov ,

The short answer is - this API is not implemented yet. At the moment we encourage to use simple API in case you need ORM.

However, it is possible: You need a thread pool...

  • You post DB request to thread pool from Coroutine (coroutine waits asynchronously without blocking the processing loop).
  • Once request is ready - result is returned back to Coroutine.

This is the way it will be implemented in the future (with some convenience APIs).

lganzzzo avatar Dec 04 '21 01:12 lganzzzo

Thank you, you have a great framework. With this feature will be the best!

MikhailNazarov avatar Dec 04 '21 06:12 MikhailNazarov

Does oatpp have a thread pool implementation? I found the Pool class - use it for a thread pool?

Do I understand correctly that for this task I need to use the IOEventWorker?

MikhailNazarov avatar Dec 04 '21 08:12 MikhailNazarov

At the moment oatpp doesn't have thread-pool implementation.

I found the Pool class - use it for a thread pool?

That pool is a kind of resource pool - it's used for ConnectionPool in ORM and Network. It also can be used for any resource. But it's not suitable for threads - just because of the performance - you don't want to start-stop new threads in the thread pool.

Do I understand correctly that for this task I need to use the IOEventWorker?

You don't have to use it directly. Oatpp does that for you.

lganzzzo avatar Dec 05 '21 02:12 lganzzzo