Load services asynchronously whenever possible (#893)

This commit is contained in:
kizer 2022-06-25 05:12:51 +09:00 committed by GitHub
parent fba8c7163c
commit 8e7f370ddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 959 additions and 899 deletions

View file

@ -12,6 +12,7 @@ namespace Dalamud.Logging.Internal
/// <summary>
/// Class responsible for tracking asynchronous tasks.
/// </summary>
[ServiceManager.EarlyLoadedService]
internal class TaskTracker : IDisposable
{
private static readonly ModuleLog Log = new("TT");
@ -20,16 +21,14 @@ namespace Dalamud.Logging.Internal
private static bool clearRequested = false;
private MonoMod.RuntimeDetour.Hook? scheduleAndStartHook;
private bool enabled = false;
/// <summary>
/// Initializes a new instance of the <see cref="TaskTracker"/> class.
/// </summary>
public TaskTracker()
[ServiceManager.ServiceConstructor]
private TaskTracker()
{
this.ApplyPatch();
var framework = Service<Framework>.Get();
framework.Update += this.FrameworkOnUpdate;
#if DEBUG
this.Enable();
#endif
}
/// <summary>
@ -102,6 +101,21 @@ namespace Dalamud.Logging.Internal
}
}
/// <summary>
/// Enables TaskTracker.
/// </summary>
public void Enable()
{
if (this.enabled)
return;
this.ApplyPatch();
var framework = Service<Framework>.Get();
framework.Update += this.FrameworkOnUpdate;
this.enabled = true;
}
/// <inheritdoc/>
public void Dispose()
{