Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use async/await for not-async io-operation? such as get/put in leveldb

I want to use async/await for database, but I don’t know how to do it.

And I found that mongodb has a async/await driver based on async conections.

But levelDB is not async.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What should I do?

I read the tokio document, may be I can use spawn_blocking to run a async io-task.

Is it right? If I frequently use spawn_blocking, will it affect the performance?

>Solution :

The spawn_blocking part of the Tokio API uses a separate thread pool (to the core threads used for async tasks) with a configurable keep-alive time if threads are unused. So you may incur the overhead of spawning a new system thread. If you’re always performing the same blocking tasks, a possible optimization could be to use a channel to communicate between async tasks and a single long running sync task which retrieves messages containing the parameters from the channel.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading