Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected virtual void Dispose(bool disposing)
{
if (disposed) return;
disposed = true;
if (TaskManager != null) TaskManager.Stop();
if (TaskManager != null) TaskManager.Dispose();
if (repositoryManager != null) repositoryManager.Dispose();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/GitHub.Api/NewTaskSystem/ITaskManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace GitHub.Unity
{
interface ITaskManager
interface ITaskManager : IDisposable
{
TaskScheduler ConcurrentScheduler { get; }
TaskScheduler ExclusiveScheduler { get; }
Expand All @@ -15,7 +16,6 @@ interface ITaskManager
T ScheduleConcurrent<T>(T task) where T : ITask;
T ScheduleExclusive<T>(T task) where T : ITask;
T ScheduleUI<T>(T task) where T : ITask;
void Stop();
Task Wait();
}
}
34 changes: 26 additions & 8 deletions src/GitHub.Api/NewTaskSystem/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TaskManager : ITaskManager
{
private static readonly ILogging logger = Logging.GetLogger<TaskManager>();

private readonly CancellationTokenSource cts;
private CancellationTokenSource cts;
private readonly ConcurrentExclusiveInterleave manager;
public TaskScheduler UIScheduler { get; set; }
public TaskScheduler ConcurrentScheduler { get { return manager.ConcurrentTaskScheduler; } }
Expand All @@ -31,12 +31,6 @@ public TaskManager(TaskScheduler uiScheduler)
this.UIScheduler = uiScheduler;
}

public void Stop()
{
cts.Cancel();
Wait();
}

public Task Wait()
{
return manager.Wait();
Expand All @@ -56,7 +50,6 @@ public static TaskScheduler GetScheduler(TaskAffinity affinity)
}
}


public void Schedule(params ITask[] tasks)
{
Guard.ArgumentNotNull(tasks, "tasks");
Expand Down Expand Up @@ -157,5 +150,30 @@ private T ScheduleConcurrent<T>(T task, bool setupFaultHandler)
}
return (T)task.Start(manager.ConcurrentTaskScheduler);
}

private void Stop()
{
if (cts == null)
throw new ObjectDisposedException(nameof(TaskManager));
cts.Cancel();
Wait();
cts = null;
}

private bool disposed = false;
private void Dispose(bool disposing)
{
if (disposed) return;
disposed = true;
if (disposing)
{
Stop();
}
}

public void Dispose()
{
Dispose(true);
}
}
}
2 changes: 1 addition & 1 deletion src/tests/IntegrationTests/BaseIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public virtual void OnSetup()
[TearDown]
public virtual void OnTearDown()
{
TaskManager.Instance?.Stop();
TaskManager.Instance?.Dispose();
Logger.Debug("Deleting TestBasePath: {0}", TestBasePath.ToString());
for (var i = 0; i < 5; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/TaskSystemIntegrationTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void OneTimeSetup()
[TestFixtureTearDown]
public void OneTimeTearDown()
{
TaskManager?.Stop();
TaskManager?.Dispose();
try
{
TestBasePath.DeleteIfExists();
Expand Down