// ✅ Good: Manager and handles stay alive for the program's lifetime
let manager = TopicManager::create()?;
let pub1 = manager.register_publisher("topic1", false, false)?;
let pub2 = manager.register_publisher("topic2", false, false)?;
let sub = manager.register_subscriber("topic1", None)?;
// Keep all handles in scope
// ... use pub1, pub2, sub ...
// ❌ Bad: Manager dropped too early
{
let manager = TopicManager::create()?;
let pub = manager.register_publisher("topic", false, false)?;
} // Manager dropped here
// Publisher may not work correctly after manager is dropped
// ❌ Bad: Subscriber handle dropped
{
let sub = manager.register_subscriber("topic", None)?;
} // Subscriber handle dropped here
// Subscription is automatically closed