diff --git a/src/client/spark/Daemons/FakeMDDaemon.cs b/src/client/spark/Daemons/FakeMDDaemon.cs index 0f543e8d6..2291a57b3 100644 --- a/src/client/spark/Daemons/FakeMDDaemon.cs +++ b/src/client/spark/Daemons/FakeMDDaemon.cs @@ -7,7 +7,8 @@ using mbts.ui; using System; using System.Collections.Generic; using System.Composition; -using System.Reactive.Linq; +using System.Threading.Tasks; +using System.Threading; using SecurityKey = System.UInt32; using MDHandle = mbts.co2.FakeMDConsumerHandle; @@ -18,10 +19,7 @@ namespace bts { // publishes a fixed set of hard coded securities to the bus, remove the line // above and this class wont be created internal class FakeMDDaemon : IShellDaemon, IDisposable { - private readonly IBus _bus; private IDisposable _dispose; - private bool _published = false; - private IReadOnlyDictionary _sec_map = _get_fake_secs(); // Returns a bunch of hard coded SecurityMD private static Dictionary _get_fake_secs() { @@ -72,19 +70,14 @@ namespace bts { [ImportingConstructor] public FakeMDDaemon(IBus bus) { bts.Log.Gen.info("FakeMDDaemon started"); - _bus = bus; - var observable = _bus.subscribe(SparkTags.SparkTimer).OnDispatcher().Subscribe( - d => _on_timer(d)); - } + var cts = new CancellationTokenSource(); + Task.Delay(TimeSpan.FromSeconds(5), cts.Token) + .ContinueWith(postFakeSecs, TaskContinuationOptions.OnlyOnRanToCompletion); + // 'Dispose' cancels the task to post securities + _dispose = Disposable.Create(cts.Cancel); - private void _on_timer(TimeSpan ts_from_start) { - if (!_published) { - if (ts_from_start.TotalSeconds >= 5) { - _published = true; - bts.Log.Gen.info("FakeMDDaemon publishing md"); - _bus.post(SparkTags.FakeSecuritiesTag, _sec_map); - } - } + void postFakeSecs(Task delayTask) => + bus.post(SparkTags.FakeSecuritiesTag, _get_fake_secs()); } public void Dispose() =>