Skip to content

Commit

Permalink
Fix Apply in SwitchC bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jam40jeff committed Jan 30, 2018
1 parent 8b5f8da commit 73cbcf9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 15 additions & 1 deletion c#/src/Sodium/Sodium.Tests/CellTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

Expand Down Expand Up @@ -149,5 +150,18 @@ public Test(int initialValue)

public CellSink<int> Value { get; }
}

[Test]
public void TestLiftCellsInSwitchC()
{
List<int> @out = new List<int>();
CellSink<int> s = new CellSink<int>(0);
Cell<Cell<int>> c = Cell.Constant(Cell.Constant(1));
Cell<Cell<int>> r = c.Map(c2 => c2.Lift(s, (v1, v2) => v1 + v2));
r.SwitchC().Listen(@out.Add);
s.Send(2);
s.Send(4);
CollectionAssert.AreEqual(new[] { 1, 3, 5 }, @out);
}
}
}
9 changes: 9 additions & 0 deletions c#/src/Sodium/Sodium/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed class Transaction
private static bool runningOnStartHooks;
private readonly HashSet<Entry> entries = new HashSet<Entry>();
private readonly List<Action<Transaction>> sendQueue = new List<Action<Transaction>>();
private bool finishedPriorityQueue;
private readonly List<Action> lastQueue = new List<Action>();
private readonly Dictionary<int, Action<Transaction>> postQueue = new Dictionary<int, Action<Transaction>>();
internal readonly List<Node.Target> TargetsToActivate;
Expand Down Expand Up @@ -348,6 +349,12 @@ internal void Prioritized(Node node, Action<Transaction> action)
this.prioritizedQueue.Enqueue(e, node.Rank);
}
this.entries.Add(e);

// we have already processed all prioritized items, so run the action now
if (this.finishedPriorityQueue)
{
action(this);
}
}

/// <summary>
Expand Down Expand Up @@ -447,6 +454,8 @@ internal void Close(bool usingLocal)
this.CheckRegen();
}

this.finishedPriorityQueue = true;

// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < this.lastQueue.Count; i++)
{
Expand Down

0 comments on commit 73cbcf9

Please sign in to comment.