neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.08k stars 892 forks source link

IEnumerator to Observable not handle inner yield exceptions #441

Open rugbbyli opened 4 years ago

rugbbyli commented 4 years ago

example:

        private IEnumerator Work1() {
            yield return null;
            yield return Work2();
        }

        private IEnumerator Work2() {
            yield return null;
            throw new Exception();
        }

        void Test() {
            Debug.LogError("test begin.");
            Observable.FromCoroutine(Work1).Subscribe(
                _ => { }, 
                err => { Debug.LogError("work1 error!"); }, 
                () => {Debug.LogError("work1 complete!");}
            );
            Observable.FromCoroutine(Work2).Subscribe(
                _ => { }, 
                err => { Debug.LogError("work2 error!"); }, 
                () => {Debug.LogError("work2 complete!");}
            );
        }

when invoke Test(), the output would be:

test begin.
work2 error!
Exception: Exception of type 'System.Exception' was thrown.

the expected output should be:

test begin.
work2 error!
work1 error!