GlitchyByte Lib  0.3.1
GlitchyByte general library to bootstrap development.
Public Member Functions | Static Public Member Functions | List of all members
gb::ShutdownMonitor Class Reference

Public Member Functions

bool shouldShutdown () const noexcept
 
void shutdown () noexcept
 
void awaitShutdown (std::chrono::milliseconds const &timeout) noexcept
 
void awaitShutdown () noexcept
 
void whileLive (std::chrono::milliseconds const &cadence, std::function< void()> const &action)
 

Static Public Member Functions

static std::shared_ptr< ShutdownMonitorcreate () noexcept
 

Detailed Description

Utility to monitor SIGINT and SIGTERM for proper application shutdown.

Member Function Documentation

◆ create()

static std::shared_ptr<ShutdownMonitor> gb::ShutdownMonitor::create ( )
inlinestaticnoexcept

Creates a monitor that will get notified when it's time for an orderly shutdown.

Returns
A shutdown monitor.

◆ shouldShutdown()

bool gb::ShutdownMonitor::shouldShutdown ( ) const
inlinenoexcept

Returns true when an orderly shutdown should occur.

Returns
True when an orderly shutdown should occur.

◆ shutdown()

void gb::ShutdownMonitor::shutdown ( )
inlinenoexcept

Manually triggers an orderly shutdown.

◆ awaitShutdown() [1/2]

void gb::ShutdownMonitor::awaitShutdown ( std::chrono::milliseconds const &  timeout)
inlinenoexcept

Awaits for a shutdown or expiration of the given timeout.

If a shutdown has been triggered, the method will exit fast.

Parameters
timeoutTime to wait for shutdown.

◆ awaitShutdown() [2/2]

void gb::ShutdownMonitor::awaitShutdown ( )
inlinenoexcept

Awaits for a shutdown.

If a shutdown has been triggered, the method will exit fast.

◆ whileLive()

void gb::ShutdownMonitor::whileLive ( std::chrono::milliseconds const &  cadence,
std::function< void()> const &  action 
)
inline

Convenience method to execute an action periodically at the given cadence, until a shutdown is triggered.

Parameters
cadenceCadence at which to execute the action.
actionAction to execute.

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