1

I try to use the RX to write a class to manager the animation sequence.unfortuntaly, I found that it does not work, when I debug it, I found that I always get the value of _sequence is null;It seems that No result is returned.I doubt that some wrong about the method AnimationSequence(). but I am not sure ,any expert can help me?

 public class AnimationManager : IDisposable
{
    private IDisposable _sequence;
    private ISequentialResult _result;

    private readonly List<Func<IObserver<ISequentialResult>, ISequentialResult, ISequentialResult>> _animationQueue
        = new List<Func<IObserver<ISequentialResult>, ISequentialResult, ISequentialResult>>();


    public void AddAnimation(Func<IObserver<ISequentialResult>, ISequentialResult, ISequentialResult> sequence)
    {
        _animationQueue.Add(sequence);
    }

    public void Run(Action<Exception> exception, Action<ISequentialResult> completed)
    {

        var sequence = AnimationSequence().ToObservable();

        _sequence = sequence.Subscribe(
            next => { },
            exception,
            () => completed(_result));
    }

    private IEnumerable<IObservable<Object>> AnimationSequence()
    {
        var x = 0;

        _result = new DefaultSeqResult(null) { Value = this };
        while (x < _animationQueue.Count)
        {
            var sequence = _animationQueue[x];


            var step = Observable.Create<ISequentialResult>(
                observer =>
                {
                    var newResult = sequence(observer, _result);
                    newResult.Results.Add(_result);
                    newResult.Results.AddRange(_result.Results);
                    _result = newResult;
                    return () => { };
                }
                );
            yield return step;

            x++;
        }

        _result.Results.Add(_result);
    }

    public void Dispose()
    {
        if (_sequence != null) _sequence.Dispose();
    }

}
4

1 に答える 1