The Async Call Helper is a C++ library designed to simplify the management of object lifetimes and enhance the safety and reliability of handling asynchronous call responses. It provides a generic solution for managing the lifetimes of objects that make asynchronous calls, ensuring that your application remains stable even when calling objects are deleted.
This library is particularly useful in scenarios where both C and C++ are used, especially in places where asynchronous calls are made. It eliminates the need to manually manage object lifetimes and reduces the risk of application crashes due to deleted objects.
- Automatic management of object lifetimes during asynchronous calls.
- Safe handling of asynchronous call responses.
- Minimal changes required in the classes that use the
async_call_helper
interface. - Customizable response handling using function pointers like lambdas or
bind
.
To use the Async Call Helper library in your project, you can clone this repository or download the source code and include it in your build system.
-
Include the
async_call_helper.h
header file in your project. -
Extend your class by inheriting
async_call_helper
.class MyService : public async_call_helper<MyService> { // ... };
-
Implement the
execute
method in your class, which will make the asynchronous call.void MyService::execute() { // Make your asynchronous call here // Pass the result to response_cb auto context = get_context<int>([this](int result) { std::cout << "result: " << result << "\n"; }); c_long_async_function(context.context, context.callback, *param); }
-
You can handle the asynchronous call response directly where you make the call or also forward to response function by using
std::bind
.void MyService::response(int result) { // Process the response here }
For a complete example of how to use the Async Call Helper, check out the sample code.
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions from the community. If you encounter any issues or have ideas for improvements, please open an issue or submit a pull request.
- The Async Call Helper library was inspired by the need for safer asynchronous call handling in C++ projects.
Disclaimer: This library is provided as-is, without any warranties or guarantees. Use it at your own risk.
For questions or support, contact Your Name.