Пример #1
0
        public PeriodicFetcherTests()
        {
            _toggles = Enumerable.Range(0, 5).Select(i => new Toggle {
                ID = Guid.NewGuid(), Name = i.ToString()
            }).ToArray();

            _client = Substitute.For <ICrispinClient>();

            _timeControl = Substitute.For <ITimeControl>();
            _timeControl
            .Delay(Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>())
            .Returns(Task.CompletedTask);
        }
Пример #2
0
        public PeriodicFetcher(ICrispinClient client, TimeSpan frequency, ITimeControl timeControl = null)
        {
            timeControl = timeControl ?? new RealTimeControl();

            _toggles         = new Dictionary <Guid, Toggle>();
            _source          = new CancellationTokenSource();
            _initialLoadDone = new TaskCompletionSource <bool>();

            _backgroundFetch = Task.Run(async() =>
            {
                await SafeReadToggles(client);
                _initialLoadDone.SetResult(true);

                while (_source.IsCancellationRequested == false)
                {
                    await timeControl.Delay(frequency, _source.Token);
                    await SafeReadToggles(client);
                }
            }, _source.Token);
        }