SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::TaskQueueProducer< T > Class Template Reference

Producer class that works across task boundaries. More...

#include <sensesp/system/task_queue_producer.h>

Inheritance diagram for sensesp::TaskQueueProducer< T >:
[legend]

Public Member Functions

 TaskQueueProducer (const T &value, std::shared_ptr< reactesp::EventLoop > consumer_event_loop, unsigned int poll_rate=990)
 
 TaskQueueProducer (const T &value, unsigned int poll_rate=990)
 
virtual void set (const T &value) override
 
bool wait (T &value, unsigned int max_duration_ms)
 Wait for a value to be available in the queue.
 
- Public Member Functions inherited from sensesp::ObservableValue< T >
 ObservableValue ()=default
 
 ObservableValue (const T &value)
 
 ObservableValue (const ObservableValue &)=delete
 
ObservableValueoperator= (const ObservableValue &)=delete
 
const T & operator= (const T &value)
 
T & operator++ ()
 
T & operator-- ()
 
operator++ (int)
 
operator-- (int)
 
const T & operator+= (const T &value)
 
const T & operator-= (const T &value)
 
- Public Member Functions inherited from sensesp::ValueConsumer< T >
virtual void set_input (const T &new_value)
 
void connect_from (ValueProducer< T > *producer)
 
- Public Member Functions inherited from sensesp::ValueProducer< T >
 ValueProducer ()
 
 ValueProducer (const T &initial_value)
 
virtual const T & get () const
 
template<typename VConsumer >
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type connect_to (std::shared_ptr< VConsumer > consumer)
 Connect a producer to a transform with a different input type.
 
template<typename VConsumer >
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer *consumer)
 
template<typename VConsumer >
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer &consumer)
 
void emit (const T &new_value)
 
- Public Member Functions inherited from sensesp::Observable
 Observable ()
 
 Observable (Observable &&other)
 Move constructor.
 
void notify ()
 
void attach (std::function< void()> observer)
 

Additional Inherited Members

- Public Types inherited from sensesp::ValueConsumer< T >
using input_type = T
 
- Protected Attributes inherited from sensesp::ValueProducer< T >
output_
 

Detailed Description

template<class T>
class sensesp::TaskQueueProducer< T >

Producer class that works across task boundaries.

Normal ObservableValues call the observer callbacks within the same task content. In a multi-task software, this is not always preferable. This class allows you to produce values in one task and consume them in another.

Template Parameters
T
Parameters
consumer_event_loopThe event loop in which the values should be consumed.
poll_rateHow often to poll the queue. Note: in microseconds! A value of 0 means that the queue will be polled on every tick.

Definition at line 80 of file task_queue_producer.h.

Constructor & Destructor Documentation

◆ TaskQueueProducer() [1/2]

template<class T >
sensesp::TaskQueueProducer< T >::TaskQueueProducer ( const T & value,
std::shared_ptr< reactesp::EventLoop > consumer_event_loop,
unsigned int poll_rate = 990 )
inline

Definition at line 82 of file task_queue_producer.h.

Here is the call graph for this function:

◆ TaskQueueProducer() [2/2]

template<class T >
sensesp::TaskQueueProducer< T >::TaskQueueProducer ( const T & value,
unsigned int poll_rate = 990 )
inline

Definition at line 101 of file task_queue_producer.h.

Member Function Documentation

◆ set()

template<class T >
virtual void sensesp::TaskQueueProducer< T >::set ( const T & new_value)
inlineoverridevirtual

Used to set an input of this consumer. It is called automatically by a ValueProducer but can also be called manually.

Parameters
new_valuethe value of the input

Reimplemented from sensesp::ObservableValue< T >.

Definition at line 104 of file task_queue_producer.h.

Here is the caller graph for this function:

◆ wait()

template<class T >
bool sensesp::TaskQueueProducer< T >::wait ( T & value,
unsigned int max_duration_ms )
inline

Wait for a value to be available in the queue.

This function will block until a value is available in the queue. When a value becomes available, it will be returned in the reference and emitted to the observers.

Parameters
valueReceived value if the function returns true.
max_duration_msMaximum duration to wait for the value.
Returns
true Value was received successfully.
false

Definition at line 118 of file task_queue_producer.h.

Here is the call graph for this function:

The documentation for this class was generated from the following file: