WPILibC++ 2024.1.1-beta-4
wpi::WorkerThread< R(T...)> Class Template Referencefinal

#include <wpinet/WorkerThread.h>

Public Types

using WorkFunction = std::function< R(T...)>
 
using AfterWorkFunction = typename detail::WorkerThreadAsync< R >::AfterWorkFunction
 

Public Member Functions

 WorkerThread ()
 
void SetLoop (uv::Loop &loop)
 Set the loop. More...
 
void SetLoop (std::shared_ptr< uv::Loop > loop)
 Set the loop. More...
 
void UnsetLoop ()
 Unset the loop. More...
 
std::shared_ptr< uv::HandleGetHandle () const
 Get the handle used by QueueWorkThen() to run afterWork. More...
 
template<typename... U>
future< R > QueueWork (WorkFunction work, U &&... u)
 Wakeup the worker thread, call the work function, and return a future for the result. More...
 
template<typename... U>
void QueueWorkThen (WorkFunction work, AfterWorkFunction afterWork, U &&... u)
 Wakeup the worker thread, call the work function, and call the afterWork function with the result on the loop set by SetLoop(). More...
 

Member Typedef Documentation

◆ AfterWorkFunction

template<typename R , typename... T>
using wpi::WorkerThread< R(T...)>::AfterWorkFunction = typename detail::WorkerThreadAsync<R>::AfterWorkFunction

◆ WorkFunction

template<typename R , typename... T>
using wpi::WorkerThread< R(T...)>::WorkFunction = std::function<R(T...)>

Constructor & Destructor Documentation

◆ WorkerThread()

template<typename R , typename... T>
wpi::WorkerThread< R(T...)>::WorkerThread ( )
inline

Member Function Documentation

◆ GetHandle()

template<typename R , typename... T>
std::shared_ptr< uv::Handle > wpi::WorkerThread< R(T...)>::GetHandle ( ) const
inline

Get the handle used by QueueWorkThen() to run afterWork.

This handle is set by SetLoop(). Calling Close() on this handle is the same as calling UnsetLoop().

Returns
The handle (if nullptr, no handle is set)

◆ QueueWork()

template<typename R , typename... T>
template<typename... U>
future< R > wpi::WorkerThread< R(T...)>::QueueWork ( WorkFunction  work,
U &&...  u 
)
inline

Wakeup the worker thread, call the work function, and return a future for the result.

It’s safe to call this function from any thread. The work function will be called on the worker thread.

The future will return a default-constructed result if this class is destroyed while waiting for a result.

Parameters
workWork function (called on worker thread)
uArguments to work function

◆ QueueWorkThen()

template<typename R , typename... T>
template<typename... U>
void wpi::WorkerThread< R(T...)>::QueueWorkThen ( WorkFunction  work,
AfterWorkFunction  afterWork,
U &&...  u 
)
inline

Wakeup the worker thread, call the work function, and call the afterWork function with the result on the loop set by SetLoop().

It’s safe to call this function from any thread. The work function will be called on the worker thread, and the afterWork function will be called on the loop thread.

SetLoop() must be called prior to calling this function for afterWork to be called.

Parameters
workWork function (called on worker thread)
afterWorkAfter work function (called on loop thread)
uArguments to work function

◆ SetLoop() [1/2]

template<typename R , typename... T>
void wpi::WorkerThread< R(T...)>::SetLoop ( std::shared_ptr< uv::Loop loop)
inline

Set the loop.

This must be called from the loop thread. Subsequent calls to QueueWorkThen will run afterWork on the provided loop (via an async handle).

Parameters
loopthe loop to use for running afterWork routines

◆ SetLoop() [2/2]

template<typename R , typename... T>
void wpi::WorkerThread< R(T...)>::SetLoop ( uv::Loop loop)
inline

Set the loop.

This must be called from the loop thread. Subsequent calls to QueueWorkThen will run afterWork on the provided loop (via an async handle).

Parameters
loopthe loop to use for running afterWork routines

◆ UnsetLoop()

template<typename R , typename... T>
void wpi::WorkerThread< R(T...)>::UnsetLoop ( )
inline

Unset the loop.

This must be called from the loop thread. Subsequent calls to QueueWorkThen will no longer run afterWork.


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