Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::AsyncLoopTimeout Struct Reference

Starts a Timeout that is invoked after expiration (relative) time has passed. More...

#include <Async.h>

Inheritance diagram for SC::AsyncLoopTimeout:
SC::AsyncRequest

Public Types

using CompletionData = AsyncCompletionData
 Completion data for AsyncLoopTimeout. More...
 
using Result = AsyncResultOf< AsyncLoopTimeout, CompletionData >
 Callback result for AsyncLoopTimeout. More...
 
- Public Types inherited from SC::AsyncRequest
enum class  Type : uint8_t {
  LoopTimeout ,
  LoopWakeUp ,
  LoopWork ,
  ProcessExit ,
  SocketAccept ,
  SocketConnect ,
  SocketSend ,
  SocketReceive ,
  SocketClose ,
  FileRead ,
  FileWrite ,
  FileClose ,
  FilePoll
}
 Type of async request. More...
 

Public Member Functions

SC::Result start (AsyncEventLoop &eventLoop, Time::Milliseconds expiration)
 Starts a Timeout that is invoked after expiration (relative) time has passed. More...
 
auto getTimeout () const
 Relative time since AsyncLoopTimeout::start after which callback will be called. More...
 
- Public Member Functions inherited from SC::AsyncRequest
void setDebugName (const char *newDebugName)
 
AsyncEventLoopgetEventLoop () const
 Get the event loop associated with this AsyncRequest. More...
 
 AsyncRequest (Type type)
 Constructs a free async request of given type. More...
 
Result stop ()
 Stops the async operation. More...
 

Public Attributes

Function< void(Result &)> callback
 Called after given expiration time since AsyncLoopTimeout::start has passed. More...
 
- Public Attributes inherited from SC::AsyncRequest
AsyncRequestnext = nullptr
 
AsyncRequestprev = nullptr
 

Friends

struct AsyncEventLoop
 

Additional Inherited Members

- Protected Member Functions inherited from SC::AsyncRequest
Result validateAsync ()
 
Result queueSubmission (AsyncEventLoop &eventLoop)
 
Result queueSubmission (AsyncEventLoop &eventLoop, ThreadPool &threadPool, AsyncTask &task)
 
- Static Protected Member Functions inherited from SC::AsyncRequest
static void updateTime (AsyncEventLoop &loop)
 
- Protected Attributes inherited from SC::AsyncRequest
AsyncEventLoopeventLoop = nullptr
 
AsyncTaskasyncTask = nullptr
 

Detailed Description

Starts a Timeout that is invoked after expiration (relative) time has passed.

// Create a timeout that will be called after 200 milliseconds
// AsyncLoopTimeout must be valid until callback is called
AsyncLoopTimeout timeout;
timeout.callback = [&](AsyncLoopTimeout::Result&)
{
console.print("My timeout has been called!");
};
// Start the timeout, that will be called 200 ms from now
SC_TRY(timeout.start(eventLoop, Time::Milliseconds(200)));
#define SC_TRY(expression)
Checks the value of the given expression and if failed, returns this value to caller.
Definition: Result.h:47
AsyncResultOf< AsyncLoopTimeout, CompletionData > Result
Callback result for AsyncLoopTimeout.
Definition: Async.h:294

Member Typedef Documentation

◆ CompletionData

◆ Result

Member Function Documentation

◆ getTimeout()

auto SC::AsyncLoopTimeout::getTimeout ( ) const
inline

Relative time since AsyncLoopTimeout::start after which callback will be called.

◆ start()

SC::Result SC::AsyncLoopTimeout::start ( AsyncEventLoop eventLoop,
Time::Milliseconds  expiration 
)

Starts a Timeout that is invoked after expiration (relative) time has passed.

Parameters
eventLoopThe event loop where queuing this async request
expirationRelative time in milliseconds from when start is called after which callback will be called
Returns
Valid Result if the request has been successfully queued

Member Data Documentation

◆ callback

Function<void(Result&)> SC::AsyncLoopTimeout::callback

Called after given expiration time since AsyncLoopTimeout::start has passed.


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