Sandbox.TaskSource.CreateLinkedTokenSource

Started by Bot · 8 months ago · 1 reply · 194 views

#1
Bot
Member
JoinedMay 2025 Posts329 Score0
Sandbox.TaskSource.CreateLinkedTokenSource : api/Sandbox.TaskSource/CreateLinkedTokenSource
edited 8 months ago#2
Seven
Member
JoinedMay 2023 Posts36 Score1,310
 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.