Use custom TaskScheduler for Framework.RunOnTick (#1597)

* Use custom TaskScheduler for Framework.RunOnTick

* TaskSchedulerWidget: add example
This commit is contained in:
srkizer 2024-03-14 08:36:38 +09:00 committed by GitHub
parent 666feede4c
commit a26bb58fdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 353 additions and 171 deletions

View file

@ -29,6 +29,11 @@ public interface IFramework
/// </summary>
public DateTime LastUpdateUTC { get; }
/// <summary>
/// Gets a <see cref="TaskFactory"/> that runs tasks during Framework Update event.
/// </summary>
public TaskFactory FrameworkThreadTaskFactory { get; }
/// <summary>
/// Gets the delta between the last Framework Update and the currently executing one.
/// </summary>
@ -44,6 +49,14 @@ public interface IFramework
/// </summary>
public bool IsFrameworkUnloading { get; }
/// <summary>
/// Returns a task that completes after the given number of ticks.
/// </summary>
/// <param name="numTicks">Number of ticks to delay.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A new <see cref="Task"/> that gets resolved after specified number of ticks happen.</returns>
public Task DelayTicks(long numTicks, CancellationToken cancellationToken = default);
/// <summary>
/// Run given function right away if this function has been called from game's Framework.Update thread, or otherwise run on next Framework.Update call.
/// </summary>
@ -65,6 +78,7 @@ public interface IFramework
/// <typeparam name="T">Return type.</typeparam>
/// <param name="func">Function to call.</param>
/// <returns>Task representing the pending or already completed function.</returns>
[Obsolete($"Use {nameof(RunOnTick)} instead.")]
public Task<T> RunOnFrameworkThread<T>(Func<Task<T>> func);
/// <summary>
@ -72,6 +86,7 @@ public interface IFramework
/// </summary>
/// <param name="func">Function to call.</param>
/// <returns>Task representing the pending or already completed function.</returns>
[Obsolete($"Use {nameof(RunOnTick)} instead.")]
public Task RunOnFrameworkThread(Func<Task> func);
/// <summary>