3 ms·
> what kind of database drivers can I use in conjunction with this? Usually synchronous database drivers have to be reimplemented in an asynchronous fashion to
by zzzcpan 11y ago
> what kind of database drivers can I use in conjunction with this?
Usually synchronous database drivers have to be reimplemented in an asynchronous fashion to work with event loops. It's not very hard though, could be as simple as adding jump tables and context structures into synchronous functions.
Emulating asynchronous execution with a thread is ok too. You do that to access filesystem anyway.
But if your first thought is about accessing a database server - you probably don't need to go asynchronous at all.
- malkia 11y ago> Emulating asynchronous execution with a thread is ok too Straying away from the topic, but I used to support a file streaming library for the game studio I worked with, and while this approach worked, some things were not gracefully handled - for example canceling reading in the middle, or somehow giving all your I/O requests to the underlying system, so it can decide what's the best way to read them (aio?).
- jhartmann 11y agoThe wangle native way of doing this is just to use an IOThreadPoolExecutor: https://github.com/facebook/wangle/blob/master/wangle/concurrent/IOThreadPoolExecutor.h https://github.com/facebook/wangle/blob/master/wangle/concur... Just make a block of threads to run your db tasks, and you can use a promise/future to return the results back to the async code.
- fredemmott 11y agoThere's https://github.com/facebook/squangle https://github.com/facebook/squangle for MySQL, though it's lacking documentation, and requires a https://github.com/facebook/mysql-5.6 https://github.com/facebook/mysql-5.6 or WebScaleSQL client library
- jcoffland 11y agoMariaDB has an asynchronous C API.
- infinite8s 11y agolibpq (Postgres's client library) has an asynchronous interface as well.