WPILibC++ 2024.1.1-beta-4
wpi::EventLoopRunner Class Reference

Executes an event loop on a separate thread. More...

#include <wpinet/EventLoopRunner.h>

Public Types

using LoopFunc = std::function< void(uv::Loop &)>
 

Public Member Functions

 EventLoopRunner ()
 
virtual ~EventLoopRunner ()
 
void Stop ()
 Stop the loop. More...
 
void ExecAsync (LoopFunc func)
 Run a function asynchronously (once) on the loop. More...
 
void ExecSync (LoopFunc func)
 Run a function synchronously (once) on the loop. More...
 
std::shared_ptr< uv::LoopGetLoop ()
 Get the loop. More...
 

Detailed Description

Executes an event loop on a separate thread.

Member Typedef Documentation

◆ LoopFunc

using wpi::EventLoopRunner::LoopFunc = std::function<void(uv::Loop&)>

Constructor & Destructor Documentation

◆ EventLoopRunner()

wpi::EventLoopRunner::EventLoopRunner ( )

◆ ~EventLoopRunner()

virtual wpi::EventLoopRunner::~EventLoopRunner ( )
virtual

Member Function Documentation

◆ ExecAsync()

void wpi::EventLoopRunner::ExecAsync ( LoopFunc  func)

Run a function asynchronously (once) on the loop.

This is safe to call from any thread, but is NOT safe to call from the provided function (it will deadlock).

Parameters
funcfunction to execute on the loop

◆ ExecSync()

void wpi::EventLoopRunner::ExecSync ( LoopFunc  func)

Run a function synchronously (once) on the loop.

This is safe to call from any thread, but is NOT safe to call from the provided function (it will deadlock). This does not return until the function finishes executing.

Parameters
funcfunction to execute on the loop

◆ GetLoop()

std::shared_ptr< uv::Loop > wpi::EventLoopRunner::GetLoop ( )

Get the loop.

If the loop thread is not running, returns nullptr.

Returns
The loop

◆ Stop()

void wpi::EventLoopRunner::Stop ( )

Stop the loop.

Once the loop is stopped it cannot be restarted. This function does not return until the loop has exited.


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