Allows for manual cancellation to be layered on top of engine-managed cancellation.
// Create our "dual triggered" token
var cts = TaskSource.CreateLinkedTokenSource();
async Task Load(TaskSource ts)
{
await ts.DelaySeconds(10, cts.Token); // Respect Both ts and cts.Token
Finish();
}
// Manually Cancel our token
cts.Cancel();
Use CancellationTokenSource when:
- You need manual cancellation
- You need to expose cancellation to callers
- Cancellation is not tied to engine lifetimes
Use TaskSource when:
- Async logic belongs to gameplay code
- Cancellation must follow engine/session rules
Use CreateLinkedTokenSource() when:
- Logic is BOTH scoped to the game and you need manual cancellation