Skip to content

Commit

Permalink
Fixed issue with cancellation of ParallelServerApi (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan authored Sep 18, 2024
1 parent 0f29aac commit 694e9e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal abstract class ParallelOperationExecutor<TOperation> : IDisposable
public int NumThreads { get; protected set; }
public bool HasStarted => Threads.Count > 0;

protected volatile bool IsDisposed;

protected abstract void ThreadMain();

protected virtual void Stop()
Expand Down Expand Up @@ -56,6 +58,7 @@ public virtual void Dispose()
Stop();
}

IsDisposed = true;
Tasks.Dispose();
}
}
6 changes: 6 additions & 0 deletions src/Speckle.Sdk/Transports/ServerUtils/ParallelServerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ protected override void ThreadMain()

while (true)
{
if (IsDisposed)
{
return;
}

var (operation, inputValue, tcs) = Tasks.Take();

if (operation == ServerApiOperation.NoOp || tcs == null)
{
return;
Expand Down

0 comments on commit 694e9e1

Please sign in to comment.