uvco 0.1
Loading...
Searching...
No Matches
uvco::TickerImpl Class Reference

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

Inheritance diagram for uvco::TickerImpl:
Collaboration diagram for uvco::TickerImpl:

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
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
119 : awaiter_{std::move(awaiter)}, count_max_{max} {}
std::unique_ptr< TimerAwaiter > awaiter_
Definition timer.cc:126
uint64_t count_max_
Definition timer.cc:127

◆ ~TickerImpl()

uvco::TickerImpl::~TickerImpl ( )
overridedefault

Member Function Documentation

◆ close()

void uvco::TickerImpl::close ( )
overridevirtual

Immediately stop the ticker.

Implements uvco::Ticker.

154 {
155 stopped_ = true;
156 // The stopped awaiter will yield a false event, and then break out of the
157 // loop (ticker() method).
158 awaiter_->resume();
159 awaiter_->stop();
160 awaiter_->close();
161}
bool stopped_
Definition timer.cc:128

◆ 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.

132 {
133 FlagGuard guard(running_);
134
135 uint64_t counter = 0;
136 while (!stopped_ && (count_max_ == 0 || counter < count_max_)) {
137 // Resumed from onMultiTimerFired():
138 if (co_await *awaiter_) {
139 if (stopped_) {
140 break;
141 }
142 co_yield counter;
143 ++counter;
144 }
145 }
146 // Clean up if not stopped manually from stop().
147 if (!stopped_) {
148 // Need to close timer so that libuv isn't blocked by the active handle on
149 // the loop.
150 close();
151 }
152}
bool running_
Definition timer.cc:129
void close() override
Immediately stop the ticker.
Definition timer.cc:154

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: