public static Action Prepare <T>(ILogger logger, IServiceProvider provider, ILease lease, T message) { var publisher = provider.GetRequiredService <IPublisher <T> >(); logger.LogTrace($"Publisher used {publisher}"); var publishing = publisher.PreparePublish(message); return(() => { var tokenSource = new CancellationTokenSource(); var publish = publishing(tokenSource.Token).ToObservable(); var releaser = Observable.Interval(lease.LeaseInterval).Select(_ => Unit.Default); releaser.TakeUntil(publish).Subscribe(_ => { if (!lease.Renew()) { tokenSource.Cancel(); tokenSource.Dispose(); lease.Dispose(); } }); publish.Subscribe(_ => { lease.Dispose(); logger.LogTrace("Published {message}", message); }, ex => logger.LogError(0, ex, "Publishing {message}", message)); }); }
protected override void Deallocate() { m_Lease.Dispose(); }
public void Dispose() { m_Output.Dispose(); m_Input.Dispose(); }