AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | List of all members
alexaClientSDK::avsCommon::utils::threading::Executor Class Reference

Single-thread executor implementation. More...

#include <Executor.h>

Public Member Functions

 Executor () noexcept
 
 Executor (const std::chrono::milliseconds &unused) noexcept
 
 ~Executor () noexcept
 
bool execute (std::function< void()> &&function) noexcept
 Schedules a function for execution. More...
 
bool execute (const std::function< void()> &function) noexcept
 Schedules a function for execution. More...
 
template<typename Task , typename... Args>
auto submit (Task task, Args &&... args) noexcept -> std::future< decltype(task(args...))>
 
template<typename Task , typename... Args>
auto submitToFront (Task task, Args &&... args) noexcept -> std::future< decltype(task(args...))>
 
void waitForSubmittedTasks () noexcept
 
void shutdown () noexcept
 Clears the executor of outstanding tasks and refuses any additional tasks to be submitted. More...
 
bool isShutdown () noexcept
 Returns whether or not the executor is shutdown. More...
 
 operator std::shared_ptr< ExecutorInterface > () const noexcept
 Provides access to ExecutorInterface reference. More...
 

Detailed Description

Single-thread executor implementation.

An Executor is used to run callable types asynchronously.

This type is a wrapper around ExecutorInterface implementation.

Constructor & Destructor Documentation

◆ Executor() [1/2]

alexaClientSDK::avsCommon::utils::threading::Executor::Executor ( )
noexcept

Constructs an Executor.

◆ Executor() [2/2]

alexaClientSDK::avsCommon::utils::threading::Executor::Executor ( const std::chrono::milliseconds &  unused)
inlinenoexcept

Constructs an Executor.

Parameters
unusedUnused parameter.
Deprecated:
This method is kept for backwards compatibility.

◆ ~Executor()

alexaClientSDK::avsCommon::utils::threading::Executor::~Executor ( )
noexcept

Destructs an Executor.

Member Function Documentation

◆ execute() [1/2]

bool alexaClientSDK::avsCommon::utils::threading::Executor::execute ( std::function< void()> &&  function)
noexcept

Schedules a function for execution.

Submits a function to be executed on an Executor thread.

Parameters
[in]functionFunction to execute. Function must not be empty.
Returns
True if function is accepted for execution, false if function is empty or executor is shutdown.

◆ execute() [2/2]

bool alexaClientSDK::avsCommon::utils::threading::Executor::execute ( const std::function< void()> &  function)
noexcept

Schedules a function for execution.

Submits a function to be executed on an Executor thread.

Parameters
[in]functionFunction to execute.
Returns
True if function is accepted for execution, false if function is empty or executor is shutdown.

◆ isShutdown()

bool alexaClientSDK::avsCommon::utils::threading::Executor::isShutdown ( )
noexcept

Returns whether or not the executor is shutdown.

◆ operator std::shared_ptr< ExecutorInterface >()

alexaClientSDK::avsCommon::utils::threading::Executor::operator std::shared_ptr< ExecutorInterface > ( ) const
noexcept

Provides access to ExecutorInterface reference.

Returns
Reference to internal ExecutorInterface.

◆ shutdown()

void alexaClientSDK::avsCommon::utils::threading::Executor::shutdown ( )
noexcept

Clears the executor of outstanding tasks and refuses any additional tasks to be submitted.

◆ submit()

template<typename Task , typename... Args>
auto alexaClientSDK::avsCommon::utils::threading::Executor::submit ( Task  task,
Args &&...  args 
) -> std::future<decltype(task(args...))>
noexcept

Submits a callable type (function, lambda expression, bind expression, or another function object) to be executed on an Executor thread. The future must be checked for validity before waiting on it.

Template Parameters
TaskCallable type.
ArgsArgument types.
Parameters
taskA callable type representing a task.
argsThe arguments to call the task with.
Returns
A std::future for the return value of the task.
Note
This method is less memory and speed efficient then execute() and should not be used unless std::future result is required.

◆ submitToFront()

template<typename Task , typename... Args>
auto alexaClientSDK::avsCommon::utils::threading::Executor::submitToFront ( Task  task,
Args &&...  args 
) -> std::future<decltype(task(args...))>
noexcept

Submits a callable type (function, lambda expression, bind expression, or another function object) to the front of the internal queue to be executed on an Executor thread. The future must be checked for validity before waiting on it.

Template Parameters
TaskCallable type.
ArgsArgument types.
Parameters
taskA callable type representing a task.
argsThe arguments to call the task with.
Returns
A std::future for the return value of the task.
Note
This method is less memory and speed efficient then execute() and should not be used unless std::future result is required.

◆ waitForSubmittedTasks()

void alexaClientSDK::avsCommon::utils::threading::Executor::waitForSubmittedTasks ( )
noexcept

Waits for any previously submitted tasks to complete.


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

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0