Method ContinueOnMainThread
- Namespace
- GrindFest
- Assembly
- GrindFest.dll
ContinueOnMainThread<T>(Task<T>, Action<T>, bool)
Continues a task execution on Unity's main thread, ensuring Unity API calls work properly. Use this instead of ContinueWith when you need to call Unity methods like Say(), Debug.Log(), etc.
public static Task ContinueOnMainThread<T>(this Task<T> task, Action<T> continuation, bool executeOnError = false)
Parameters
taskTask<T>The task to continue
continuationAction<T>The action to execute on the main thread with the task result
executeOnErrorboolWhether to execute the continuation even if the task faulted (default: false)
Returns
- Task
A task that completes when the continuation finishes
Type Parameters
TThe result type of the task
Examples
Think("Some prompt").ContinueOnMainThread(result => {
Say(result); // Safe to call Unity APIs here
Debug.Log("AI result: " + result);
});
Think<BattleDecision>("Analyze battle").ContinueOnMainThread(decision => {
Say($"I will {decision.Action}"); // Safe Unity API calls
});
ContinueOnMainThread(Task, Action, bool)
Continues a non-generic task execution on Unity's main thread.
public static Task ContinueOnMainThread(this Task task, Action continuation, bool executeOnError = false)
Parameters
taskTaskThe task to continue
continuationActionThe action to execute on the main thread
executeOnErrorboolWhether to execute the continuation even if the task faulted (default: false)
Returns
- Task
A task that completes when the continuation finishes