VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
schedule.h File Reference

RAII task scheduling wrapper with delay, priority, timeouts and result chaining. More...

#include <atomic>
#include <cstdint>
#include <functional>
#include <memory>
#include <mutex>
#include <vector>
#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

 Non-constructible utility struct providing task scheduling primitives. More...
 Scheduling parameters for a task posted via MessageLoop::exec_task(). More...
 RAII handle returned by exec_task() for a void-callback task. More...
 RAII handle returned by exec_task() for a bool-returning callback task. More...

Namespaces

Detailed Description

RAII task scheduling wrapper with delay, priority, timeouts and result chaining.

Schedule is a utility namespace (implemented as a non-constructible struct) that wraps a callable in a Config envelope and produces a Status or RetStatus RAII handle. The handle lets callers register continuation callbacks in a fluent style:

loop.exec_task(vlink::Schedule::Config{0, 100}, // no delay, priority 100
[]() -> bool { return do_work(); })
.on_then([] { on_success(); })
.on_else([] { on_failure(); })
.on_catch([](std::exception& e) { on_error(e); })
.on_schedule_timeout([] { on_not_started_in_time(); })
.on_execution_timeout([] { on_took_too_long(); });

Config fields:

Field Meaning
delay_ms Delay before the task is posted (via one-shot Timer)
priority Task dispatch priority (for kPriorityType loop)
schedule_timeout_ms If the task is not started within this time, fire the timeout
execution_timeout_ms If the task runs longer than this, fire the timeout callback
Note
  • Status is move-only; copying is disabled. The internal state is reference-counted via std::shared_ptr<StatusImpl>, so it is safe to return by value.
  • RetStatus adds on_then (fires when callback returns true) and on_else (fires when callback returns false).
  • Callbacks are invoked from the MessageLoop thread.
Example
loop.async_run();
// Void callback with execution timeout:
loop.exec_task(vlink::Schedule::Config{100}, // 100 ms delay
[] { expensive_op(); })
.on_execution_timeout([] { VLOG_W("slow!"); });
// Bool callback with result chaining:
[]() -> bool { return try_connect(); })
.on_then([] { start_session(); })
.on_else([] { retry_later(); });
#define VLOG_W(...)
Definition logger.h:852