Skip to content

Commit

Permalink
Fixed Trampoline could not be reused
Browse files Browse the repository at this point in the history
  • Loading branch information
TORISOUP committed May 28, 2024
1 parent b245f9f commit be9ae6d
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 be9ae6d

Please sign in to comment.