7#include "platforms/coroutine.h"
17 ss << fl::get<0>(trace) <<
":" <<
fl::get<1>(trace);
24 return id.fetch_add(1) + 1;
64 platforms::ICoroutineTask::exitCurrent();
68 platforms::TaskCoroutinePtr
mImpl;
87 virtual
int id() const = 0;
222 config.core_id.has_value() ? config.core_id.
value() : -1)) {}
279 if (!
mImpl->is_auto_registered()) {
280 mImpl->auto_register_with_scheduler();
296 mImpl->set_canceled();
string str() const FL_NO_EXCEPT
platforms::TaskCoroutinePtr mImpl
Coroutine(fl::string name, TaskFunction function, size_t stack_size=4096, u8 priority=5, int core_id=-1)
fl::function< void()> TaskFunction
static void exitCurrent()
~Coroutine() FL_NO_EXCEPT=default
unique_ptr< string > mTraceLabel
void execute_catch(const Error &) override
bool ready_to_run_frame_task(fl::u32) const override
void auto_register_with_scheduler() override
bool ready_to_run(fl::u32) const override
CoroutineTask(const CoroutineConfig &config)
void set_id(int id) override
void execute_then() override
TaskType type() const override
string trace_label() const override
void set_last_run_time(fl::u32) override
bool is_canceled() const override
void set_then(function< void()>) override
bool is_auto_registered() const override
int interval_ms() const override
bool has_then() const override
bool isRunning() const override
bool has_catch() const override
unique_ptr< Coroutine > mCoroutine
void set_catch(function< void(const Error &)>) override
void set_interval_ms(int) override
void set_canceled() override
fl::u32 last_run_time() const override
int interval_ms() const FL_NO_EXCEPT
Returns the interval between runs, in milliseconds.
void set_last_run_time(u32 time) FL_NO_EXCEPT
Records the timestamp of the most recent run.
u32 last_run_time() const FL_NO_EXCEPT
Returns the timestamp of the most recent run, in milliseconds.
Handle & then(function< void()> on_then) FL_NO_EXCEPT
Sets the callback invoked when the task runs successfully.
bool has_then() const FL_NO_EXCEPT
Returns whether a success callback is configured.
bool _has_then() const FL_NO_EXCEPT
int _id() const FL_NO_EXCEPT
void _execute_catch(const Error &error) FL_NO_EXCEPT
void _execute_then() FL_NO_EXCEPT
Handle & catch_(function< void(const Error &)> on_catch) FL_NO_EXCEPT
Sets the callback invoked when task execution reports an error.
bool _is_canceled() const FL_NO_EXCEPT
void stop() FL_NO_EXCEPT
Stops the coroutine represented by this handle.
bool _ready_to_run(u32 current_time) const FL_NO_EXCEPT
Handle & cancel() FL_NO_EXCEPT
Prevents future scheduled executions of the task.
void set_interval_ms(int interval_ms) FL_NO_EXCEPT
Changes the interval between runs.
bool is_valid() const FL_NO_EXCEPT
Returns whether this handle refers to a task.
bool isRunning() const FL_NO_EXCEPT
Returns whether the represented coroutine is currently running.
int id() const FL_NO_EXCEPT
Returns the task's unique identifier.
bool has_catch() const FL_NO_EXCEPT
Returns whether an error callback is configured.
bool isCoroutine() const FL_NO_EXCEPT
Returns whether this handle refers to an OS-level coroutine.
TaskType _type() const FL_NO_EXCEPT
Handle() FL_NO_EXCEPT=default
Constructs an empty, invalid handle.
string _trace_label() const FL_NO_EXCEPT
bool ready_to_run(u32 current_time) const FL_NO_EXCEPT
Tests whether the task is ready at a given timestamp.
bool _ready_to_run_frame_task(u32 current_time) const FL_NO_EXCEPT
void _set_last_run_time(u32 time) FL_NO_EXCEPT
string trace_label() const FL_NO_EXCEPT
Returns the label of the task's creation trace, if available.
void _set_id(int id) FL_NO_EXCEPT
shared_ptr< ITaskImpl > mImpl
TaskType type() const FL_NO_EXCEPT
Returns the task's scheduling mode.
Task Handle with fluent API (was class fl::task, renamed to avoid namespace collision)
virtual bool is_auto_registered() const =0
virtual TaskType type() const =0
virtual void set_id(int id)=0
virtual bool has_catch() const =0
virtual void execute_then()=0
virtual void set_canceled()=0
virtual bool isRunning() const =0
virtual void set_interval_ms(int interval_ms)=0
virtual bool ready_to_run(u32 current_time) const =0
virtual string trace_label() const =0
virtual int interval_ms() const =0
virtual void set_last_run_time(u32 time)=0
virtual void set_catch(function< void(const Error &)> on_catch)=0
virtual bool ready_to_run_frame_task(u32 current_time) const =0
virtual void auto_register_with_scheduler()=0
virtual ~ITaskImpl() FL_NO_EXCEPT=default
virtual bool is_canceled() const =0
virtual bool has_then() const =0
virtual void set_then(function< void()> on_then)=0
virtual void execute_catch(const Error &error)=0
virtual u32 last_run_time() const =0
static Scheduler & instance()
void execute_catch(const Error &error) override
void set_interval_ms(int interval_ms) override
string trace_label() const override
void execute_then() override
TimeTask(TaskType type, int interval_ms, optional< TracePoint > trace=nullopt)
bool is_canceled() const override
bool isRunning() const override
u32 last_run_time() const override
void set_id(int id) override
void set_canceled() override
bool is_auto_registered() const override
TaskType type() const override
bool ready_to_run(u32 current_time) const override
void set_catch(function< void(const Error &)> on_catch) override
void auto_register_with_scheduler() override
int interval_ms() const override
unique_ptr< string > mTraceLabel
void set_then(function< void()> on_then) override
bool has_then() const override
bool has_catch() const override
function< void()> mThenCallback
void set_last_run_time(u32 time) override
function< void(const Error &)> mCatchCallback
bool ready_to_run_frame_task(u32) const override
string make_trace_label(const TracePoint &trace)
Handle before_frame()
Frame tasks recur: every overload below schedules a task that runs once per FastLED frame and keeps d...
Handle after_frame()
Creates a task that runs after every FastLED frame until canceled.
Handle coroutine(const CoroutineConfig &config)
Creates and starts an OS-level coroutine task.
Handle at_framerate(int fps)
Creates a task that runs at a fixed frame rate.
Handle every_ms(int interval_ms)
Creates a task that runs at a fixed millisecond interval.
TaskType
Identifies how a scheduled task is triggered.
@ kBeforeFrame
Runs immediately before each FastLED frame is rendered.
@ kAfterFrame
Runs immediately after each FastLED frame is rendered.
@ kAtFramerate
Runs at a fixed number of times per second.
@ kEveryMs
Runs after a fixed time interval.
@ kCoroutine
Runs as an operating-system or RTOS task.
void exit_current()
Terminates the currently executing coroutine.
Function and platform tuning for an OS-level coroutine task.
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
constexpr int type_rank< T >::value
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NO_EXCEPT
fl::u64 time() FL_NO_EXCEPT
Alias for millis64() - returns 64-bit millisecond time.
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
InputGamut g FL_NO_EXCEPT
constexpr nullopt_t nullopt
pair_element< I, T1, T2 >::type & get(pair< T1, T2 > &p) FL_NO_EXCEPT
fl::tuple< const char *, int, fl::u32 > TracePoint
A structure to hold source trace information.
Base definition for an LED controller.
Task scheduler — manages timer and frame-based tasks.
static constexpr T max() FL_NO_EXCEPT