コード例 #1
0
ファイル: WWWExample.cs プロジェクト: wjezxujian/UnityCourse
        protected override IDisposable SubscribeCore(IObserver <T> observer, IDisposable cancel)
        {
            var fromCoroutineObserver = new FromCoroutine(observer, cancel);

#if (NETFX_CORE || NET_4_6 || NET_STANDARD_2_0 || UNITY_WSA_10_0)
            var moreCancel = new CancellationDisposable();
            var token      = moreCancel.Token;
#else
            var moreCancel = new BooleanDisposable();
            var token      = new CancellationToken(moreCancel);
#endif

            MainThreadDispatcher.SendStartCoroutine(coroutine(fromCoroutineObserver, token));

            return(moreCancel);
        }
コード例 #2
0
        public static IObservable <TResult> StartAsync <TResult>(Func <CancellationToken, UniTask <TResult> > functionAsync)
        {
            var cancellable = new CancellationDisposable();

            var task = default(UniTask <TResult>);

            try
            {
                task = functionAsync(cancellable.Token);
            }
            catch (Exception exception)
            {
                return(Throw <TResult>(exception));
            }

            var result = task.ToObservable();

            return(Create <TResult>(observer =>
            {
                var subscription = result.Subscribe(observer);
                return new CompositeDisposable(cancellable, subscription);
            }));
        }