Skip to content

Commit

Permalink
Merge pull request #212 from TORISOUP/fix_Trampoline
Browse files Browse the repository at this point in the history
Fixed Trampoline could not be reused
  • Loading branch information
neuecc authored May 28, 2024
2 parents f89d807 + be9ae6d commit f1cc928
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/R3/Operators/Trampoline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void DrainMessages()

if (!queue.TryDequeue(out value))
{
running = false;
return;
}
}
Expand Down
38 changes: 38 additions & 0 deletions tests/R3.Tests/OperatorTests/TrampolineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,42 @@ public void Trampoline()
C : OnPlayerAddTeam
""");
}


[Fact]
public void TrampolineIsReusable()
{
var sender = new Subject<string>();
var receiver = sender.Trampoline().Share();

var log = new List<string>();

// A
receiver.Subscribe(x =>
{
log.Add(x);
if (x == "OnPlayerJoined") sender.OnNext("OnPlayerAddTeam");
});

sender.OnNext("OnPlayerJoined");

var msg = string.Join(Environment.NewLine, log);

msg.Should().Be("""
OnPlayerJoined
OnPlayerAddTeam
""");

// reset logs
log.Clear();

// send again
sender.OnNext("OnPlayerJoined");

msg = string.Join(Environment.NewLine, log);
msg.Should().Be("""
OnPlayerJoined
OnPlayerAddTeam
""");
}
}

0 comments on commit f1cc928

Please sign in to comment.