[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/mmitkevich/cpp.react/master/examples/src/BasicReactors.cpp [Back]  [Original]

//          Copyright Sebastian Jeckel 2014.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#include 
#include 
#include 

#include "react/Domain.h"
#include "react/Signal.h"
#include "react/Event.h"
#include "react/Reactor.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
/// Example 1 - Creating reactive loops
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace example1
{
    using namespace std;
    using namespace react;

    REACTIVE_DOMAIN(D, sequential)
    USING_REACTIVE_DOMAIN(D)

    using PointT = pair;
    using PathT  = vector;

    vector paths;

    EventSourceT mouseDown = MakeEventSource();
    EventSourceT mouseUp   = MakeEventSource();
    EventSourceT mouseMove = MakeEventSource();

    ReactorT loop
    {
        [] (ReactorT::Context ctx)
        {
            PathT points;

            points.emplace_back(ctx.Await(mouseDown));

            ctx.RepeatUntil(mouseUp, [&] {
                points.emplace_back(ctx.Await(mouseMove));
            });

            points.emplace_back(ctx.Await(mouseUp));

            paths.push_back(points);
        }
    };

    void Run()
    {
        cout 

Web Proxy Viewer  |  New URL  |  Original Page