subhadipbhowmik / 30-Days-Of-CPP

30 days of CPP programming challenge is a step by step guide to learn CPP programming language in 30 days. Happy Coding.
https://subhadipbhowmik.github.io/30-Days-Of-CPP/
MIT License
48 stars 138 forks source link

added the documentation of Asynchronous Data Processing with Coroutin… #478

Open Ayushi-Choudhary22 opened 6 days ago

Ayushi-Choudhary22 commented 6 days ago

Asynchronous Data Processing with Coroutines

Description

In this project, we explore asynchronous data processing using C++20 coroutines. Asynchronous processing allows operations to execute independently of the main program flow, enabling the main program to continue executing without waiting for these operations to complete. This technique is particularly useful for improving the performance and responsiveness of applications.

Key Concepts

  1. Coroutines: Coroutines are functions that can suspend and resume execution at multiple points. In C++, coroutines are introduced in C++20 and enable writing asynchronous code that appears synchronous.
  2. Promise Object: Manages the coroutine's state and defines how the coroutine is initialized, suspended, resumed, and finalized.
  3. Coroutine Handle: A handle to the coroutine's state, used to resume or destroy the coroutine.
  4. Awaitable and Awaiter: Objects that define the behavior of the co_await keyword. They provide methods (await_ready, await_suspend, and await_resume) to control the suspension and resumption of the coroutine.

Implementation Overview

Coroutine and Awaitable

The core of the implementation involves defining a coroutine and an awaitable object. The coroutine uses the co_await keyword to wait for the completion of an asynchronous task represented by the awaitable object.

Benefits of Coroutines

Conclusion

Coroutines in C++20 provide a powerful mechanism for asynchronous data processing. They enable writing clear, readable, and maintainable asynchronous code that can efficiently manage operations without blocking the main program flow. By leveraging coroutines, developers can handle complex asynchronous tasks in a more straightforward and less error-prone manner.

Ayushi-Choudhary22 commented 6 days ago

hey @subhadipbhowmik ! please review my PR and accept it so that I can contribute more in GSSOC'24.

Ayushi-Choudhary22 commented 3 days ago

hey @subhadipbhowmik ! please review my PR and accept it so that I can contribute more in GSSOC'24.