MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Showcase::GeneratorValueStream< Generator > Class Template Reference

Wraps results of multiple value generators to a single value stream. More...

#include <GeneratorValueStream.hpp>

Inheritance diagram for Showcase::GeneratorValueStream< Generator >:
Showcase::ValueStream< Generator::ValueType >

Public Member Functions

 GeneratorValueStream (std::shared_ptr< folly::Executor > generatorExecutor)
 Executor that is given as a parameter to generators.
 
virtual ~GeneratorValueStream ()
 Futures that are out will be fulfilled, but the order of the values is not ensured. More...
 
virtual folly::Future< ValueType > next () override
 
void setSynchronizationTest (std::function< bool(const ValueType &)> f)
 This function tests whether the value received is so called 'synchronization' value. More...
 
void setCallback (std::function< void(const ValueType &)> f)
 Add callback to be executed for every value that flows through the stream.
 
void addGenerator (GeneratorPtr generator)
 Must be called before next on this stream.
 
- Public Member Functions inherited from Showcase::ValueStream< Generator::ValueType >
int forEachSync (const std::function< void(const Generator::ValueType &)> &f, int N, const std::function< bool(const Generator::ValueType &)> &endCond=nullptr)
 Executes f for each next N values in the Stream as long as values are being generated. More...
 

Detailed Description

template<typename Generator>
class Showcase::GeneratorValueStream< Generator >

Wraps results of multiple value generators to a single value stream.

Behaves like an infinite queue

Constructor & Destructor Documentation

template<typename Generator >
Showcase::GeneratorValueStream< Generator >::~GeneratorValueStream ( )
virtual

Futures that are out will be fulfilled, but the order of the values is not ensured.

In other words one can have pending elements between non pending elements even if all underlying generators wouldn't have reached pending state. Basically this allows tapping into the raw stream generators provide. The lifetime of underlying generator is tied to the futures sent out.

Add tasks from generators to the futures sent out that have not yet been taken care of

only assign to generators that haven't been disabled

Capture generator for ensuring the proper calculation

Member Function Documentation

template<typename Generator >
folly::Future< typename GeneratorValueStream< Generator >::ValueType > Showcase::GeneratorValueStream< Generator >::next ( )
overridevirtual

Double checked locking pattern a'la MULTI_ONCE

Already have some fulfilled promises in stock

Need to make new promise for this request

Launch some new computation on generators that are finished

Implements Showcase::ValueStream< Generator::ValueType >.

template<typename Generator >
void Showcase::GeneratorValueStream< Generator >::setSynchronizationTest ( std::function< bool(const ValueType &)>  f)

This function tests whether the value received is so called 'synchronization' value.

  • When synchronization value is received from single generator the execution for that generator is paused.
  • After all generators have reached synchronization value single synchronization value is sent and the execution of all generators is continued.