VLink  2.0.0
A high-performance communication middleware
schedule.h File Reference

Fluent task-scheduling wrapper used by MessageLoop::exec_task() and family. More...

#include <atomic>
#include <cstdint>
#include <memory>
#include <mutex>
#include <vector>
#include "./functional.h"
#include "./macros.h"
Include dependency graph for schedule.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  vlink::Schedule
 Non-instantiable container for task-scheduling types and the process() entry points. More...
 
struct  vlink::Schedule::Config
 Scheduling parameters captured at the call to exec_task(). More...
 
class  vlink::Schedule::Status
 RAII handle returned by exec_task() when the wrapped callback returns void. More...
 
struct  vlink::Schedule::Status::Impl
 
class  vlink::Schedule::RetStatus
 RAII handle returned by exec_task() when the wrapped callback returns bool. More...
 

Namespaces

 

Detailed Description

Fluent task-scheduling wrapper used by MessageLoop::exec_task() and family.

vlink::Schedule is a non-instantiable utility struct that wraps a user callable in a Config envelope and produces a Status (or RetStatus for bool-returning callbacks) RAII handle. The handle lets callers attach continuation callbacks in a fluent style, including success/failure branches, exception handling, and scheduling/execution timeout hooks.

Categories of options carried by Schedule::Config:

Field Purpose
delay_ms Wait before posting via a one-shot Timer.
priority Dispatch priority for priority-aware message loops.
schedule_timeout_ms Maximum queue-wait budget after the delay. Triggered once when the
task is dequeued. Drops the task on expiry.
execution_timeout_ms Maximum execution budget per callback in the chain. Reported once
after each callback returns; never interrupts a running callback.

Status surface exposed to the caller:

*   exec_task() -> Status / RetStatus
*                    +--> on_schedule_timeout(cb)
*                    +--> on_execution_timeout(cb)
*                    +--> on_catch(cb)
*                    +--> [RetStatus] on_then(cb)
*                    +--> [RetStatus] on_else(cb)
* 
Note
  • Status is move-only and may be returned by value while it is being configured.
  • The wrapped task is not posted to its dispatcher until the configuration handle is committed (when it is destroyed, i.e. the end of the fluent expression). This guarantees that every continuation attached through the chain is registered before the task runs, so a fast dispatcher can never win a race against the caller and drop a continuation.
  • Callers that store the handle instead of consuming it inline must call dispatch() to post the task immediately; otherwise it is posted only when the stored handle is destroyed.
  • All continuation callbacks run on the dispatcher thread that ran the wrapped task.
Example
loop.async_run();
[] { do_work(); })
.on_execution_timeout([] { VLOG_W("slow"); });
[]() -> bool { return try_connect(); })
.on_then([] { start_session(); })
.on_else([] { schedule_retry(); });
#define VLOG_W(...)
Definition: logger.h:787