trophy 0
May 2025 109 posts
Sandbox.TaskSource.CreateLinkedTokenSource : api/Sandbox.TaskSource/CreateLinkedTokenSource
trophy 820
May 2023 32 posts
Seven 25 days ago edited 12 days ago
 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

people
Log in to reply
You can't reply if you're not logged in. That would be crazy.