Skip to content

Game.SceneFlow.AsyncHelpers

Assembly:
Assembly-CSharp.dll (typical for Cities: Skylines 2 runtime types)
Namespace: Game.SceneFlow

Type:
static class

Base:
System.Object (static classes are sealed and abstract by compiler)

Summary:
Provides a small async helper extension method to wait for a Task with a timeout. The extension method returns a boolean indicating whether the target Task completed before the timeout elapsed. It uses Task.Delay and Task.WhenAny under the hood. Note: this method does not cancel or await the original task beyond checking its completion, nor does it propagate exceptions from the target task — it only reports whether the task finished in time.


Fields

  • None

Properties

  • None

Constructors

  • None (static class)

Methods

  • public static System.Threading.Tasks.Task<bool> AwaitWithTimeout(this System.Threading.Tasks.Task task, System.TimeSpan timeout)
    Extension method that waits up to the provided timeout for the supplied Task to complete. Returns true if the task completed before the timeout, false if the delay finished first. Implementation detail: it creates a Task via Task.Delay(timeout) and uses Task.WhenAny(task, delay). It does not cancel the original Task if the timeout occurs, and it does not rethrow exceptions from the target task — callers should observe/await the task separately if they need exceptions or want to await its completion.

Usage Example

using System;
using System.Threading.Tasks;
using Game.SceneFlow; // bring the extension into scope

// Example usage in an async method:
public async Task ExampleUsage(Task someTask)
{
    TimeSpan timeout = TimeSpan.FromSeconds(5);
    bool completedInTime = await someTask.AwaitWithTimeout(timeout);

    if (completedInTime)
    {
        // someTask finished within 5 seconds.
        // If you need exceptions or the result (for Task<T>) you should still await the task itself:
        // await someTask; // observe exceptions or get result (if Task<T>).
    }
    else
    {
        // Timed out. someTask may still be running; it's not cancelled by AwaitWithTimeout.
    }
}

Additional notes: - Make sure the extension's namespace (Game.SceneFlow) is imported where you use it. - For Task, the extension works because Task derives from Task; to access the task result you still need to await the original Task. - If you need cancellation support or to propagate exceptions immediately when the task completes, use CancellationToken-aware patterns or explicitly await/observe the original task after the timeout check.