Skip to content
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
17 changes: 9 additions & 8 deletions Source/Advisor/ApprovalManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using RimMind.Advisor.Settings;
Expand All @@ -19,7 +20,7 @@ public class CabinetProposal

public class ApprovalManager
{
private static readonly Dictionary<RequestEntry, Pawn> _pendingRequests = new Dictionary<RequestEntry, Pawn>();
private static readonly ConcurrentDictionary<RequestEntry, Pawn> _pendingRequests = new ConcurrentDictionary<RequestEntry, Pawn>();
private readonly RimMindAdvisorSettings _settings;

public ApprovalManager(RimMindAdvisorSettings settings)
Expand Down Expand Up @@ -68,7 +69,7 @@ public static void CancelPendingForPawn(Pawn? pawn)

foreach (var entry in toCancel)
{
_pendingRequests.Remove(entry);
_pendingRequests.TryRemove(entry, out _);
try
{
if (!RimMindAPI.DismissPendingRequest(entry))
Expand Down Expand Up @@ -124,7 +125,7 @@ public RequestEntry SubmitForApproval(
options = new[] { approveLabel, rejectLabel },
callback = choice =>
{
if (entryRef != null) _pendingRequests.Remove(entryRef);
if (entryRef != null) _pendingRequests.TryRemove(entryRef, out _);
if (choice == approveLabel)
{
onApproved();
Expand All @@ -136,7 +137,7 @@ public RequestEntry SubmitForApproval(
},
completionCallback = completionReason =>
{
if (entryRef != null) _pendingRequests.Remove(entryRef);
if (entryRef != null) _pendingRequests.TryRemove(entryRef, out _);
if (completionReason == RequestCompletionReason.Selected)
return;

Expand All @@ -159,7 +160,7 @@ public RequestEntry SubmitForApproval(
}
catch
{
_pendingRequests.Remove(entry);
_pendingRequests.TryRemove(entry, out _);
try
{
if (!RimMindAPI.DismissPendingRequest(entry))
Expand Down Expand Up @@ -233,7 +234,7 @@ public RequestEntry SubmitCabinetProposal(
options = new[] { approveAllLabel, dismissLabel },
callback = choice =>
{
if (entryRef != null) _pendingRequests.Remove(entryRef);
if (entryRef != null) _pendingRequests.TryRemove(entryRef, out _);
if (choice == approveAllLabel)
{
foreach (var cb in proposal.ExecutionCallbacks)
Expand All @@ -256,7 +257,7 @@ public RequestEntry SubmitCabinetProposal(
},
completionCallback = completionReason =>
{
if (entryRef != null) _pendingRequests.Remove(entryRef);
if (entryRef != null) _pendingRequests.TryRemove(entryRef, out _);
if (completionReason == RequestCompletionReason.Selected)
return;

Expand All @@ -279,7 +280,7 @@ public RequestEntry SubmitCabinetProposal(
}
catch
{
_pendingRequests.Remove(entry);
_pendingRequests.TryRemove(entry, out _);
try
{
if (!RimMindAPI.DismissPendingRequest(entry))
Expand Down
1 change: 1 addition & 0 deletions Tests/Contracts/ColonyMacroPerceiverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace RimMind.Advisor.Tests.Contracts
{
[Collection("Advisor runtime")]
public class ColonyMacroPerceiverTests
{
[Fact]
Expand Down
Loading