简体   繁体   中英

C++: Datastax CassFuture to BoostAsio Awaitable

I would like to turn the CassFuture Object from Datastax's C++ Driver to a Boost Asio Awaitable Object. The problem is it seems like this conversion could induce additional overhead as I would effectively be wrapping a future around another future. Does anyone have any smart ideas or useful insights or worst case a way to approach this that minimally wastes computational effort?

I have considered the idea of creating a for loop where when it checks the future and the future yields no result (ie. no error or result) that it simply passes priority back to the io_context, but this seems inefficient and arbitrary versus leaving and the scheduling to the built in io_context scheduler.

You could use the callback handler. From the linked page:

A callback can be set on a future to notify the client application when a request has completed. Using a future callback is the lowest latency method of notification when waiting for several asynchronous operations.

I have not delved into the documentation to find out exactly which threads could invoke the callback. If you want to completely isolate from the implementation detail, you could always post a handler onto the Asio service.

To be completely Asio compatible (including asio::use_future , asio::use_awaitable etc), you could implement an async initiation function using the Completion Token pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM