MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Showcase::CachingGenerator< GeneratorType > Class Template Referenceabstract

This generator type abstracts the following type of generator: More...

#include <GraphGenerators.hpp>

Inherits GeneratorType, and Showcase::Notifiable.

Public Member Functions

virtual folly::Future< ValueType > next (folly::Executor *executor=nullptr) override
 
virtual void changeObserved () override
 

Detailed Description

template<typename GeneratorType>
class Showcase::CachingGenerator< GeneratorType >

This generator type abstracts the following type of generator:

  • Generator can only read 'the whole state' of the target
  • There is some external mechanism that is able to detect that change may have happened

The generator operates as following way:

  1. Read the whole state and return "found"-events for item followed by a pending event
  2. Hibernate into state where futures are returned if asked but never fulfilled
  3. When some external entity calls 'changeObserved'-event read the whole state again and fill as many futures with possible events as there exists
  4. If there are more events than there were futures, cache the events and hand them until there are no events cached anymore.
  5. Return to step 3.

This is used for example with FileSystem- and Database- generators

Member Function Documentation

template<typename GeneratorType >
void Showcase::CachingGenerator< GeneratorType >::changeObserved ( )
overridevirtual

Only update cache if there are futures to be fulfilled

Note
assumption here is that this is called in some background thread so it should be ok to fulfill promises right here. on the other hand we could also put this to same executor which is given in next()-calls
template<typename GeneratorType >
folly::Future< typename GeneratorType::ValueType > Showcase::CachingGenerator< GeneratorType >::next ( folly::Executor *  executor = nullptr)
overridevirtual

This function is only called by executor for this event if that is non null