示例#1
0
        private void Subscribe(IUserActor userActor)
        {
            Log.Info($"{_user.Login}");

            if (_syncSubscription != null)
            {
                throw new InvalidOperationException("Already subscribed to changes.");
            }

            var start = new ChangeSummary();

            start.Add(userId: _user.UserId);

            // Changes streamed from the queue
            _syncSubscription = _syncManager.Changes
                                .ObserveOn(TaskPoolScheduler.Default)
                                .StartWith(start) // Run an initial sync no matter what.
                                .Select(c =>
                                        Observable.FromAsync(() => _syncContext.Sync(c))
                                        .Catch <Unit, Exception>(LogError <Unit>))
                                .Concat() // Force sequential evaluation
                                .Subscribe();

            // Polling for updates
            _pollSubscription = _PollInterval
                                .ObserveOn(TaskPoolScheduler.Default)
                                .StartWith(0)
                                .Select(_ =>
                                        Observable.FromAsync(() => userActor.Sync())
                                        .Catch <Unit, Exception>(LogError <Unit>))
                                .Concat() // Force sequential evaluation
                                .Subscribe();
        }