Add docs to task fulfill and reject

This commit is contained in:
Alessandro Proto 2023-03-17 22:46:43 +01:00
parent 44437e84f1
commit 63838e97c7

View file

@ -44,27 +44,32 @@ public class TaskMeta : IComponent
} }
public class RuntimeTask public class RuntimeTask
{ {
public RuntimeTask(string name) public RuntimeTask(string name = "object")
{ {
Name = name; Name = name;
} }
public RuntimeTask() { }
public Guid Guid { get; set; } = Guid.NewGuid(); public Guid Guid { get; set; } = Guid.NewGuid();
public string Name { get; set; } = "object"; public string Name { get; set; }
public TaskStatus Status { get; set; } = TaskStatus.Running; public TaskStatus Status { get; set; } = TaskStatus.Running;
public string Error { get; private set; } public string Error { get; private set; }
public int DataIndex { get; private set; } = 0; public int DataIndex { get; private set; } = 0;
public bool UserTask { get; set; } = false; public bool UserTask { get; set; } = false;
/// <summary>
/// Pops one element at the top of the container (lk) stack and uses it as task value.
///
/// The container must contain a value and cannot be nil.
/// </summary>
/// <param name="lk"></param>
/// <exception cref="Exception">Throws if the value nil or the stack is empty</exception>
public void Fulfill(Action<Lua> lk) public void Fulfill(Action<Lua> lk)
{ {
Status = TaskStatus.Succeeded; Status = TaskStatus.Succeeded;
var container = tasks.NewThread(); var container = tasks.NewThread();
lk(container); lk(container);
if(container.IsNil(-1)) if(container.IsNoneOrNil(-1))
{ {
throw new Exception("Task result cannot be nil"); throw new Exception("Task result cannot be nil");
} }
@ -95,6 +100,11 @@ public class TaskMeta : IComponent
}); });
} }
/// <summary>
/// Rejects the task with an error message.
/// </summary>
/// <param name="error"></param>
/// <param name="args"></param>
public void Reject(string error, params object[] args) public void Reject(string error, params object[] args)
{ {
Status = TaskStatus.Failed; Status = TaskStatus.Failed;