Skip to content

One time event (long schedule) #44

@lablabla

Description

@lablabla

Hi,

I have a need for a TmLongSchedule but it should only run once.
Is there a reason for not having such option?

Currently I'm thinking of doing something like this. Storing the created task id, and inside the lambda function, retrieve it and cancel the task

auto taskId = taskManager.registerEvent(new TmLongSchedule(next_run*1000, [this, &event]() {    
    taskid_t taskIdToCancel = this->getTaskId(event.id);
    taskManager.cancelTask(taskIdToCancel);

    // do task after long wait
}), true);

if (taskId == TASKMGR_INVALIDID)
{
    log_e("Failed scheduling task");
    return;
}
m_jobs[event.id] = taskId;

It seems to work but it seems like a relatively hacky way of doing this, considering for "short" schedule there exists a scheduleOnce

Is there a better way of doing this that I'm missing?

Thanks for this great project!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions