Giter Club home page Giter Club logo

recpp's Introduction

Overview

GitHub Actions Workflow Status Maintenance GitHub License

Welcome to ReCpp, a sophisticated C++ library for reactive programming that builds on the Reactive Streams standard and leverages the ReactiveX model.

This library, powered by the RsCpp implementation of the Reactive Streams standard, empowers developers to create clean, concise, and efficient asynchronous and event-driven code with ease.

Features

  • Reactive Streams Standard: ReCpp is built on top of the RsCpp implementation of the Reactive Streams standard, providing a consistent and interoperable API for handling asynchronous data streams.

  • Functional Reactive Programming (FRP): Embrace the paradigm of FRP to model complex asynchronous workflows with a clear and functional approach.

  • Comprehensive Operators: Enjoy a rich set of operators inspired by the ReactiveX model, enabling effortless manipulation and transformation of data streams.

  • Backpressure Handling: Efficiently manage backpressure to ensure your application remains responsive and scalable, even in high-load scenarios.

  • Extensibility: Easily extend the library with your own custom operators or integrate it with existing codebases.

Why use ReCpp over other asynchronous technologies ?

Callback hell

ReCpp avoid the callback hell, when multiple callbacks are nested into each other. ReCpp allows you to chain your callbacks in a linear way and handle errors more easily. For example :

// Callback hell
asyncFunction1(
    []()
    {
        asyncFunction2(
            []()
            {
                doSomething();
            },
            [](const auto &error)
            {
                std::cerr << error.what() << std::endl;
            });
    },
    [](const auto &error)
    {
        std::cerr << error.what() << std::endl;
    });

// ReCpp chaining
rxAsyncFunction1()
    .andThen(rxAsyncFunction2())
    .subscribe(
        []()
        {
            doSomething();
        },
        [](const auto &error)
        {
            std::cerr << error.what() << std::endl;
        });

Coroutines

Even if c++20 coroutines offers a really great standard solution for asynchronous programming, ReCpp has some advantages over them:

  • natively forward errors which leads to a higher resiliency
  • faster to write
  • easier to read
  • bring powerful operators to create highly performant asynchronous code that would be hard to create with coroutines
  • backpressure handling

Supported platforms

  • Windows
  • MacOS
  • Ubuntu

Getting started

Installation

You want to integrate ReCpp to your project ? Check our installation guide

Documentation

Explore the Documentation to learn more about ReCpp.

Interoperability

ReCpp can easily interoperate with other asynchronous programming systems. Here are some examples:

Callbacks

// The async function that uses callbacks
void asyncFunction(const std::function<void(int)> &onSuccess, const std::function<void(const std::exception_ptr &)> onError);

// The ReCpp equivalent
recpp::Single<int> rxAsyncFunctionWrapper()
{
    return recpp::Single<int>::create(
        [](auto &subscriber) // Lambda called on subscription
        {
            asyncFunction(
                [subscriber](int result) // Lambda called on asyncFunction success
                {
                    subscriber.onNext(result); // Emit the value and complete the Single
                },
                [](const auto &error) // Lambda called on asyncFunction error
                {
                    subscriber.onError(error); // Emit the error
                });
        });
}

Coroutines

// The async function that uses coroutines
task<std::expected<int, std::exception_ptr>> asyncFunction();

// The ReCpp equivalent
recpp::Single<int> rxAsyncFunctionWrapper()
{
    return recpp::Single<int>::create(
        [](auto &subscriber) // Lambda called on subscription
        {
            const auto result = asyncFunction().get();
            if (result.has_value())
                subscriber.onNext(result.value());
            else
                subscriber.onError(result.error());
        });
}

RxCpp

// The rxcpp function
rxcpp::observable<int> rxcppAsyncFunction();

// The ReCpp equivalent
recpp::Observable<int> recppAsyncFunction()
{
    return recpp::Observable<int>::create(
        [](auto &subscriber) // Lambda called on subscription
        {
            rxcppAsyncFunction()
                .subscribe(
                    [subscriber](auto value)
                    {
                        subscriber.onNext(value);
                    },
                    [subscriber](auto error)
                    {
                        subscriber.onError(error);
                    },
                    [subscriber]()
                    {
                        subscriber.onComplete();
                    }
                );
        });
}

License

ReCpp is licensed under the MIT License. See the LICENSE file for details.

Contributing

We welcome contributions from the community! Whether you want to report a bug, request a feature, or submit a pull request, please follow our Contribution Guidelines.

recpp's People

Contributors

pribault avatar pribaultc avatar

Stargazers

Andrés Brugarolas avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.