cppcoro | A library of C++ coroutine abstractions for the coroutines TS | Android library

 by   lewissbaker C++ Version: Current License: MIT

kandi X-RAY | cppcoro Summary

kandi X-RAY | cppcoro Summary

cppcoro is a C++ library typically used in Mobile, Android applications. cppcoro has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

The 'cppcoro' library provides a large set of general-purpose primitives for making use of the coroutines TS proposal described in N4680. This library is an experimental library that is exploring the space of high-performance, scalable asynchronous programming abstractions that can be built on top of the C++ coroutines proposal. It has been open-sourced in the hope that others will find it useful and that the C++ community can provide feedback on it and ways to improve it.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              cppcoro has a medium active ecosystem.
              It has 2812 star(s) with 407 fork(s). There are 118 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 88 open issues and 55 have been closed. On average issues are closed in 82 days. There are 21 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of cppcoro is current.

            kandi-Quality Quality

              cppcoro has 0 bugs and 0 code smells.

            kandi-Security Security

              cppcoro has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              cppcoro code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              cppcoro is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              cppcoro releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.
              It has 99 lines of code, 6 functions and 1 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cppcoro
            Get all kandi verified functions for this library.

            cppcoro Key Features

            No Key Features are available at this moment for cppcoro.

            cppcoro Examples and Code Snippets

            No Code Snippets are available at this moment for cppcoro.

            Community Discussions

            QUESTION

            What's the special value of `co_yield` in contrast to a simple stateful lambda in C++20?
            Asked 2021-Dec-30 at 20:02

            From the well-known C++ coroutine library (search "Don't allow any use of co_await inside the generator coroutine." in the source file generator.hpp), and from my own experiments, I know that a coroutine using co_yield cannot use co_await meanwhile.

            Since a generator using co_yield must be synchronous, then, what's the advantage of using co_yield over a simple stateful lambda?

            For example:

            ...

            ANSWER

            Answered 2021-Dec-30 at 19:16

            For trivial generators with minimal internal state and code, a small functor or lambda is fine. But as your generator code becomes more complex and requires more state, it becomes less fine. You have to stick more members in your functor type or your lambda specifier. You have bigger and bigger code inside of the function. Etc.

            At the most extreme, a co_yield-based generator can hide all of its implementation details from the outside world, simply by putting its definition in a .cpp file. A stateful functor cannot hide its internal state, as its state are members of the type, which the outside world must see. The only way to avoid that is through type-erasure, such as with something like std::function. At which point, you've gained basically nothing over just using co_yield.

            Also, co_await can be used with co_yield. Cppcoro's generator type explicitly hoses it, but cppcoro isn't C++20. You can write whatever generator you want, and that generator can support uses of co_await for specific purposes.

            Indeed, you can make asynchronous generators, where sometimes you can yield a value immediately, and sometimes you can schedule the availability of a value with some asynchronous process. The code invoking your async generator can co_await on it to extract values from it, rather than treating it like a functor or an iterator pair.

            Source https://stackoverflow.com/questions/70535616

            QUESTION

            Communicating between coroutines in ASIO
            Asked 2021-Aug-13 at 13:42

            I have a coroutine that listens asynchronously on an asio UDP socket. When it receives a message it co_spawns a new co-routine to handle the message and then goes back to listening on the port. This new coroutine may need to do additional communication on the same UDP socket. What is a good way to make sure the replies to the requests that the second coroutine makes comes back to it?

            I was thinking of making some kind of future to store the reply that the new coroutine can co_await but it doesn't seem to be avaible in asio and it doesn't look to be easy to make. I could store a function object that get's called when a reply comes but then what's the point of coroutines in the first place? I could have the new coroutine listen to the same socket but which coroutine will then get the reply? Either? Both?

            To summarize: I want to be able to suspend the new coroutine until I get a reply and when I do get a reply in the original coroutine I want it to resume the new coroutine. Basically I want something like cppcoro::single_consumer_event

            ...

            ANSWER

            Answered 2021-Aug-13 at 13:42

            I figured out a decent solution but I would love to find a better one. I can create a future class that contains an asio::steady_timer. Then I can handle timeouts in a neat way and I can just call cancel the timer when the original coroutine gets a reply. Seems pretty overkill and steady_timer is huge (112 bytes?!) but if it works then it works...

            Source https://stackoverflow.com/questions/68742051

            QUESTION

            C++20 Coroutines and iostream
            Asked 2021-Apr-29 at 20:04

            I am playing around with C++ 20's Coroutines. The sample is compiled with clang++.

            The compiler error I am facing is

            error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream') and 'cppcoro::generator')

            which is about the following line

            ...

            ANSWER

            Answered 2021-Apr-29 at 20:04

            From the documentation of cppcoro::generator, the only "meaningful" operations you can do to a generator is get begin and end iterators via begin() and end(). This is precisely why your second use for (auto n : generatorForNumbers(0, 5)) works. It iterates over the generator. Though you technically hit undefined behavior since there's no stopping condition for the generator so it overflows an int.

            You can't print the generator directly. You have to iterate over it. So you could do this instead:

            Source https://stackoverflow.com/questions/67324038

            QUESTION

            co_return vs. co_yield when the right hand side is a temporary
            Asked 2021-Apr-20 at 04:50

            Background: This question arose when I was reading the source of cppcoro, specifically this line.

            Question: Consider the following code:

            ...

            ANSWER

            Answered 2021-Apr-20 at 04:46

            You are breaking a cardinal rule of C++: you wrote a function that takes a potential prvalue and store a pointer that outlives the function call that gave them a prvalue. Indeed, any time you see a function that takes an rvalue-reference (or a const-lvalue-reference) and stores a pointer/reference to that object which will outlive that function, you should consider that code to be highly dubious at best.

            If a function takes a parameter as an rvalue reference, that means you're expected to either use it or move from it within that function call. Prvalues are not normally expected to outlive the function call they are passed to, so you either use them or lose them.

            In any case, the behavior you're seeing is exactly what you're supposed to see. When a coroutine issues a co_return, it... returns. That means the main body of the coroutine block has exited. return_value is called while the block still exists, but once that is done, the coroutine block and all of its automatic variables (including parameters) go away.

            This is why returning references to automatic variables from a normal function is a bad idea. This is just as bad an idea for co_return, even if you're indirectly shepherding that reference to the caller.

            The co_yield version works (you still shouldn't do it, because that's not how you're supposed to treat prvalues, but it is required to work) because the co_yield statement itself is told to suspend by the return value of yield_value. This preserves the coroutine's stack, including any prvalues that were within the co_yield statement itself until the coroutine is resumed.

            But again, you should do the move in the yield_value function, just as you would for rvalue reference parameters normally.

            Source https://stackoverflow.com/questions/67172316

            QUESTION

            Cppcoro not accepting result from an constom awaitable struct
            Asked 2021-Jan-18 at 14:36

            I decided to write my own awaitable in order to loader to learn how C++ coroutine works. For now, I want to build my own struct that is equivalent to this:

            ...

            ANSWER

            Answered 2021-Jan-18 at 14:36

            The problem is, I think, that you declared your return type as task but you don't actually co_return any int.

            Does the problem go away if you co_return n?

            Source https://stackoverflow.com/questions/65770499

            QUESTION

            Why not use std::memory_order_acq_rel
            Asked 2020-Dec-07 at 17:25

            ANSWER

            Answered 2020-Dec-07 at 13:25

            The operations on the atomic variable itself will not cause data races either way.

            std::memory_order_release means that all modified cached data will be committed to shared memory / RAM. Memory order operations generate memory fences so other objects could be properly committed to / read from shared memory.

            Source https://stackoverflow.com/questions/65182051

            QUESTION

            C++: How to properly use generator<>, task<>, and lazy<> classes available in #include?
            Asked 2020-Oct-26 at 20:26

            I gather (from here) that the coroutine types is broadly classified into 3:

            generator<> , task<>, and lazy<>

            My question is: What is the difference between the three if I'm wanting to decide on the return type?

            For example: What would be the return class for a co-routine that lazy-loads a set of file handlers? My implementation would use task and generator to achieve the same.

            I've looked this under the 'execution' section regarding the restrictions on the promise object when it interacts with the coroutine. But I can only find implementation differences rather than methodology differences.

            ...

            ANSWER

            Answered 2020-Oct-26 at 20:26

            I did some research and I believe the answer is as follows:

            First, there is no lazy<> class in C++. The https://en.cppreference.com/w/cpp/language/coroutines has it wrong. (Refer the draft for confirmation)

            So, it's a matter of distinction between the return type of generator and task.

            TLDR;

            The easiest way to remember is:

            generators are associated with co_yield; whereas, tasks are associated with co_await

            generator

            The co_yield mechanism associated with the generator class is exactly the same as what we would encounter in python (refer the docs) and also much similar to the thread_suspend concept in operating system mechanisms.

            You may choose to implement it synchronously or asynchronously. (Refer the cppcoro library for samples.)

            A generator type (kind-of) looks like this:

            Source https://stackoverflow.com/questions/64542433

            QUESTION

            Turning a function call which takes a callback into a coroutine
            Asked 2020-Oct-09 at 15:56

            I am exploring and trying to learn C++ Coroutines (added in C++20). An SDK I am using has asynchronous API calls which all take a callback, the callbacks are invoked on some background thread managed by the SDK.

            ...

            ANSWER

            Answered 2020-Oct-09 at 15:56

            There's a really good article by Raymond Chen, you can find it here.

            In your case, you can do something like this.

            Source https://stackoverflow.com/questions/64270626

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install cppcoro

            You can download it from GitHub.

            Support

            GitHub issues are the primary mechanism for support, bug reports and feature requests. Contributions are welcome and pull-requests will be happily reviewed. I only ask that you agree to license any contributions that you make under the MIT license. If you have general questions about C++ coroutines, you can generally find someone to help in the #coroutines channel on Cpplang Slack group.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/lewissbaker/cppcoro.git

          • CLI

            gh repo clone lewissbaker/cppcoro

          • sshUrl

            git@github.com:lewissbaker/cppcoro.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link