uvco 0.1
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
uvco::TickerImpl Class Reference

Non-movable, non-copyable: because the awaiter is called by a callback. More...

Inheritance diagram for uvco::TickerImpl:
Inheritance graph
[legend]
Collaboration diagram for uvco::TickerImpl:
Collaboration graph
[legend]

Public Member Functions

 TickerImpl (const TickerImpl &)=delete
 
 TickerImpl (TickerImpl &&)=default
 
TickerImploperator= (const TickerImpl &)=delete
 
TickerImploperator= (TickerImpl &&)=default
 
 TickerImpl (std::unique_ptr< TimerAwaiter > awaiter, uint64_t max)
 
 ~TickerImpl () override=default
 
MultiPromise< uint64_t > ticker () override
 
Promise< void > close () override
 Immediately stop the ticker.
 
- Public Member Functions inherited from uvco::Ticker
 Ticker ()=default
 
virtual ~Ticker ()=default
 

Private Attributes

std::unique_ptr< TimerAwaiterawaiter_
 
uint64_t count_max_
 
bool stopped_ = false
 
bool running_ = false
 

Detailed Description

Non-movable, non-copyable: because the awaiter is called by a callback.

Constructor & Destructor Documentation

◆ TickerImpl() [1/3]

uvco::TickerImpl::TickerImpl ( const TickerImpl )
delete

◆ TickerImpl() [2/3]

uvco::TickerImpl::TickerImpl ( TickerImpl &&  )
default

◆ TickerImpl() [3/3]

uvco::TickerImpl::TickerImpl ( std::unique_ptr< TimerAwaiter awaiter,
uint64_t  max 
)
inline
138 : awaiter_{std::move(awaiter)}, count_max_{max} {}
std::unique_ptr< TimerAwaiter > awaiter_
Definition timer.cc:145
uint64_t count_max_
Definition timer.cc:146

◆ ~TickerImpl()

uvco::TickerImpl::~TickerImpl ( )
overridedefault

Member Function Documentation

◆ close()

Promise< void > uvco::TickerImpl::close ( )
overridevirtual

Immediately stop the ticker.

Implements uvco::Ticker.

173 {
174 stopped_ = true;
175 // The stopped awaiter will yield a false event, and then break out of the
176 // loop (ticker() method).
177 awaiter_->resume();
178 awaiter_->stop();
179 co_await awaiter_->close();
180}
bool stopped_
Definition timer.cc:147

◆ operator=() [1/2]

TickerImpl & uvco::TickerImpl::operator= ( const TickerImpl )
delete

◆ operator=() [2/2]

TickerImpl & uvco::TickerImpl::operator= ( TickerImpl &&  )
default

◆ ticker()

MultiPromise< uint64_t > uvco::TickerImpl::ticker ( )
overridevirtual

A promise generating successive integers. If a count was given upon creation, the last tick after reaching 0 will yield std::nullopt.

Implements uvco::Ticker.

151 {
152 FlagGuard guard(running_);
153
154 uint64_t counter = 0;
155 while (!stopped_ && (count_max_ == 0 || counter < count_max_)) {
156 // Resumed from onMultiTimerFired():
157 if (co_await *awaiter_) {
158 if (stopped_) {
159 break;
160 }
161 co_yield counter;
162 ++counter;
163 }
164 }
165 // Clean up if not stopped manually from stop().
166 if (!stopped_) {
167 // Need to close timer so that libuv isn't blocked by the active handle on
168 // the loop.
169 co_await close();
170 }
171}
bool running_
Definition timer.cc:148
Promise< void > close() override
Immediately stop the ticker.
Definition timer.cc:173

Member Data Documentation

◆ awaiter_

std::unique_ptr<TimerAwaiter> uvco::TickerImpl::awaiter_
private

◆ count_max_

uint64_t uvco::TickerImpl::count_max_
private

◆ running_

bool uvco::TickerImpl::running_ = false
private

◆ stopped_

bool uvco::TickerImpl::stopped_ = false
private

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