Method code for $scheduler.sys_add_task()

[Turn on line numbering]
arg time, method, sender, caller, flags, @args;
var task, i, j, tid, x, y, tmpq, task_time;

// use `@info $scheduler' for more information. 
// [tid, time, time(), sender(), caller(), method, flags, args]
//
if (!$sys.is_agent(sender()))
    throw(~perm, "Sender is not an agent or admin, use .add_task()");
if (type(time) != 'integer || type(method) != 'symbol || type(args) != 'list)
    throw(~type, "Arguments are not an integer, symbol, and list.");
if (time < 1)
    throw(~time, "Time is negative.");
if (time > 31536000)
    throw(~time, "Try to schedule a task LESS than a year from now?");
if (!valid(sender))
    throw(~type, "The argument for sender is not a valid object");
if (!valid(caller))
    throw(~type, "The argument for caller is not a valid object");
if (type(flags) != 'list)
    throw(~type, "Send flags as a list of symbols");

//
++task_index;
tid = task_index;
task_time = time();

// flags can be set in a system only add_task, for now set them as 'system
task = [tid, task_time + time, task_time, sender, caller, method, flags, args];
.add_to_task_queue(task);
return tid;

// Miroslav Silovic
// Created 05-Sep-1995 as a part of ColdCore, see: @help Credit

Tlon