Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::AsyncLoopTimeout Struct Reference

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

#include <Async.h>

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

Public Types

using CompletionData = AsyncCompletionData
 
using Result = AsyncResultOf<AsyncLoopTimeout, CompletionData>
 
- 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 relativeTimeout)
 Sets async request members and calls AsyncEventLoop::start.
 
Time::Absolute getExpirationTime () const
 Gets computed absolute expiration time that determines when this timeout get executed.
 
- Public Member Functions inherited from SC::AsyncRequest
void setDebugName (const char *newDebugName)
 
AsyncEventLoopgetEventLoop () const
 Get the event loop associated with this AsyncRequest.
 
void cacheInternalEventLoop (AsyncEventLoop &loop)
 Caches the event loop associated with this AsyncRequest.
 
Result setThreadPoolAndTask (ThreadPool &pool, AsyncTask &task)
 Sets the thread pool and task to use for this request.
 
void resetThreadPoolAndTask ()
 Resets anything previously set with setThreadPoolAndTask.
 
 AsyncRequest (Type type)
 Constructs a free async request of given type.
 
Result stop (Function< void(AsyncResult &)> *afterStopped=nullptr)
 Ask to stop current async operation.
 
bool isFree () const
 Returns true if this request is free.
 
bool isCancelling () const
 Returns true if this request is being cancelled.
 
bool isActive () const
 Returns true if this request is active or being reactivated.
 
Type getType () const
 Returns request type.
 
Result start (AsyncEventLoop &loop)
 Shortcut for AsyncEventLoop::start.
 

Public Attributes

Function< void(Result &)> callback
 Called after given expiration time since AsyncLoopTimeout::start has passed.
 
Time::Milliseconds relativeTimeout
 First timer expiration (relative) time in milliseconds.
 
- Public Attributes inherited from SC::AsyncRequest
AsyncRequestnext = nullptr
 
AsyncRequestprev = nullptr
 

Friends

struct AsyncEventLoop
 

Additional Inherited Members

- Protected Member Functions inherited from SC::AsyncRequest
Result checkState ()
 
void queueSubmission (AsyncEventLoop &eventLoop)
 
- Protected Attributes inherited from SC::AsyncRequest
AsyncEventLoopeventLoop = nullptr
 
AsyncTaskasyncTask = nullptr
 

Detailed Description

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

Note
For a periodic timeout, call AsyncLoopTimeout::Result::reactivateRequest(true) in the completion callback
// Create a timeout that will be called after 200 milliseconds
// AsyncLoopTimeout must be valid until callback is called
AsyncLoopTimeout timeout;
timeout.callback = [&](AsyncLoopTimeout::Result& res)
{
console.print("My timeout has been called!");
if (someCondition) // Optionally re-activate the timeout if needed
{
// Schedule the timeout callback to fire again 100 ms from now
res.getAsync().relativeTimeout = Time::Milliseconds(100);
res.reactivateRequest(true);
}
};
// Start the timeout, that will be called 200 ms from now
SC_TRY(timeout.start(eventLoop, 200_ms));

Member Function Documentation

◆ getExpirationTime()

Time::Absolute SC::AsyncLoopTimeout::getExpirationTime ( ) const
inline

Gets computed absolute expiration time that determines when this timeout get executed.

◆ start()

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

Sets async request members and calls AsyncEventLoop::start.

Member Data Documentation

◆ callback

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

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

◆ relativeTimeout

Time::Milliseconds SC::AsyncLoopTimeout::relativeTimeout

First timer expiration (relative) time in milliseconds.


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