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
task
Task<T>The task to continue
continuation
Action<T>The action to execute on the main thread with the task result
executeOnError
boolWhether to execute the continuation even if the task faulted (default: false)
Returns
- Task
A task that completes when the continuation finishes
Type Parameters
T
The 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
task
TaskThe task to continue
continuation
ActionThe action to execute on the main thread
executeOnError
boolWhether to execute the continuation even if the task faulted (default: false)
Returns
- Task
A task that completes when the continuation finishes