mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[ntcore] Revamp listeners (#4511)
- In both C++ and Java, add listener functions to Instance class (same as NT3 provided) - Add WaitForListenerQueue functions (same as NT3 provided) - Move Java non-poller implementation to Instance (previously only handled single instance) - Change C++ listeners to take non-const references for subscribers etc to help avoid footguns from use of temporary objects (also add doc comment) - Fix Preferences making .type persistent
This commit is contained in:
@@ -89,12 +89,10 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
wpi::mutex m;
|
||||
std::vector<nt::ConnectionNotification> result;
|
||||
auto handle = nt::AddConnectionListener(
|
||||
server_inst,
|
||||
[&](const nt::ConnectionNotification& event) {
|
||||
server_inst, false, [&](const nt::ConnectionNotification& event) {
|
||||
std::scoped_lock lock{m};
|
||||
result.push_back(event);
|
||||
},
|
||||
false);
|
||||
});
|
||||
|
||||
// trigger a connect event
|
||||
Connect(GetParam().first, 0, 20001 + GetParam().second);
|
||||
@@ -116,6 +114,9 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
nt::StopClient(client_inst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
// wait for thread
|
||||
nt::WaitForConnectionListenerQueue(server_inst, 1.0);
|
||||
|
||||
// get the event
|
||||
{
|
||||
std::scoped_lock lock{m};
|
||||
|
||||
Reference in New Issue
Block a user