Merge remote-tracking branch 'origin/master' into net8-rollup

This commit is contained in:
github-actions[bot] 2024-03-19 03:11:08 +00:00
commit 990f04715f
4 changed files with 314 additions and 26 deletions

View file

@ -108,9 +108,6 @@ internal sealed class Framework : IInternalDisposableService, IFramework
/// <inheritdoc/>
public DateTime LastUpdateUTC { get; private set; } = DateTime.MinValue;
/// <inheritdoc/>
public TaskFactory FrameworkThreadTaskFactory { get; }
/// <inheritdoc/>
public TimeSpan UpdateDelta { get; private set; } = TimeSpan.Zero;
@ -130,6 +127,11 @@ internal sealed class Framework : IInternalDisposableService, IFramework
/// </summary>
internal bool DispatchUpdateEvents { get; set; } = true;
private TaskFactory FrameworkThreadTaskFactory { get; }
/// <inheritdoc/>
public TaskFactory GetTaskFactory() => this.FrameworkThreadTaskFactory;
/// <inheritdoc/>
public Task DelayTicks(long numTicks, CancellationToken cancellationToken = default)
{
@ -143,6 +145,38 @@ internal sealed class Framework : IInternalDisposableService, IFramework
return tcs.Task;
}
/// <inheritdoc/>
public Task RunOnFrameworkThreadAwaitable(Action action, CancellationToken cancellationToken = default)
{
if (cancellationToken == default)
cancellationToken = this.FrameworkThreadTaskFactory.CancellationToken;
return this.FrameworkThreadTaskFactory.StartNew(action, cancellationToken);
}
/// <inheritdoc/>
public Task<T> RunOnFrameworkThreadAwaitable<T>(Func<T> action, CancellationToken cancellationToken = default)
{
if (cancellationToken == default)
cancellationToken = this.FrameworkThreadTaskFactory.CancellationToken;
return this.FrameworkThreadTaskFactory.StartNew(action, cancellationToken);
}
/// <inheritdoc/>
public Task RunOnFrameworkThreadAwaitable(Func<Task> action, CancellationToken cancellationToken = default)
{
if (cancellationToken == default)
cancellationToken = this.FrameworkThreadTaskFactory.CancellationToken;
return this.FrameworkThreadTaskFactory.StartNew(action, cancellationToken).Unwrap();
}
/// <inheritdoc/>
public Task<T> RunOnFrameworkThreadAwaitable<T>(Func<Task<T>> action, CancellationToken cancellationToken = default)
{
if (cancellationToken == default)
cancellationToken = this.FrameworkThreadTaskFactory.CancellationToken;
return this.FrameworkThreadTaskFactory.StartNew(action, cancellationToken).Unwrap();
}
/// <inheritdoc/>
public Task<T> RunOnFrameworkThread<T>(Func<T> func) =>
this.IsInFrameworkUpdateThread || this.IsFrameworkUnloading ? Task.FromResult(func()) : this.RunOnTick(func);
@ -198,7 +232,9 @@ internal sealed class Framework : IInternalDisposableService, IFramework
this.DelayTicks(delayTicks, cancellationToken),
},
_ => func(),
cancellationToken);
cancellationToken,
TaskContinuationOptions.HideScheduler,
this.frameworkThreadTaskScheduler);
}
/// <inheritdoc/>
@ -223,7 +259,9 @@ internal sealed class Framework : IInternalDisposableService, IFramework
this.DelayTicks(delayTicks, cancellationToken),
},
_ => action(),
cancellationToken);
cancellationToken,
TaskContinuationOptions.HideScheduler,
this.frameworkThreadTaskScheduler);
}
/// <inheritdoc/>
@ -248,7 +286,9 @@ internal sealed class Framework : IInternalDisposableService, IFramework
this.DelayTicks(delayTicks, cancellationToken),
},
_ => func(),
cancellationToken).Unwrap();
cancellationToken,
TaskContinuationOptions.HideScheduler,
this.frameworkThreadTaskScheduler).Unwrap();
}
/// <inheritdoc/>
@ -273,7 +313,9 @@ internal sealed class Framework : IInternalDisposableService, IFramework
this.DelayTicks(delayTicks, cancellationToken),
},
_ => func(),
cancellationToken).Unwrap();
cancellationToken,
TaskContinuationOptions.HideScheduler,
this.frameworkThreadTaskScheduler).Unwrap();
}
/// <summary>
@ -498,9 +540,6 @@ internal class FrameworkPluginScoped : IInternalDisposableService, IFramework
/// <inheritdoc/>
public DateTime LastUpdateUTC => this.frameworkService.LastUpdateUTC;
/// <inheritdoc/>
public TaskFactory FrameworkThreadTaskFactory => this.frameworkService.FrameworkThreadTaskFactory;
/// <inheritdoc/>
public TimeSpan UpdateDelta => this.frameworkService.UpdateDelta;
@ -518,10 +557,29 @@ internal class FrameworkPluginScoped : IInternalDisposableService, IFramework
this.Update = null;
}
/// <inheritdoc/>
public TaskFactory GetTaskFactory() => this.frameworkService.GetTaskFactory();
/// <inheritdoc/>
public Task DelayTicks(long numTicks, CancellationToken cancellationToken = default) =>
this.frameworkService.DelayTicks(numTicks, cancellationToken);
/// <inheritdoc/>
public Task RunOnFrameworkThreadAwaitable(Action action, CancellationToken cancellationToken = default) =>
this.frameworkService.RunOnFrameworkThreadAwaitable(action, cancellationToken);
/// <inheritdoc/>
public Task<T> RunOnFrameworkThreadAwaitable<T>(Func<T> action, CancellationToken cancellationToken = default) =>
this.frameworkService.RunOnFrameworkThreadAwaitable(action, cancellationToken);
/// <inheritdoc/>
public Task RunOnFrameworkThreadAwaitable(Func<Task> action, CancellationToken cancellationToken = default) =>
this.frameworkService.RunOnFrameworkThreadAwaitable(action, cancellationToken);
/// <inheritdoc/>
public Task<T> RunOnFrameworkThreadAwaitable<T>(Func<Task<T>> action, CancellationToken cancellationToken = default) =>
this.frameworkService.RunOnFrameworkThreadAwaitable(action, cancellationToken);
/// <inheritdoc/>
public Task<T> RunOnFrameworkThread<T>(Func<T> func)
=> this.frameworkService.RunOnFrameworkThread(func);