public TurtlesimPublish(string topic, IMessageDispatcher messageDispatcher) { InitializeComponent(); Loaded += TurtlesimPublish_Loaded; Closing += TurtlesimPublish_Closing; _publisher = new Publisher <Twist>(topic, messageDispatcher, new RosMessageTypeAttributeHelper()); _viewModel = new TurtlesimPublishViewModel(topic, MIN_STEP, MAX_STEP); }
public static void WaitForAnySubscriber(this IRosPublisher publisher, CancellationToken token = default) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } Task.Run(() => publisher.WaitForAnySubscriberAsync(token), token).WaitAndRethrow(); }
public static void WaitForAnySubscriber(this IRosPublisher publisher, int timeoutInMs) { using CancellationTokenSource tokenSource = new(timeoutInMs); try { publisher.WaitForAnySubscriber(tokenSource.Token); } catch (OperationCanceledException) { throw new TimeoutException("Wait for subscriber timed out"); } }
public static async Task WaitForAnySubscriberAsync(this IRosPublisher publisher, CancellationToken token = default) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (publisher.NumSubscribers != 0) { return; } using var linkedSource = CancellationTokenSource.CreateLinkedTokenSource(token, publisher.CancellationToken); while (publisher.NumSubscribers == 0) { await Task.Delay(200, linkedSource.Token); } }
private async void TurtlesimPublish_Closing(object sender, System.ComponentModel.CancelEventArgs e) { await _publisher.UnadvertiseAsync(); _publisher = null; }