/// <summary>
 /// Disposes of managed memory for the class.
 /// </summary>
 /// <param name="disposing">If this method is being called by the Dispose method.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _queuedOps?.Dispose();
         _shutdownObs?.Dispose();
     }
 }
        private void OnDestroy()
        {
            // Observableがまだ動いていたら止める
            _disposable?.Dispose();

            // AsyncSubjectを破棄
            _onTimeUpAsyncSubject.Dispose();
        }
Example #3
0
 /// <summary>
 /// Disposes of the resources.
 /// </summary>
 /// <param name="disposing">A value indicating whether the instance is disposing.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _appearing.Dispose();
         PageDisposables.Dispose();
     }
 }
Example #4
0
        public void HasObservers_Dispose3()
        {
            var s = new AsyncSubject <int>();

            Assert.IsFalse(s.HasObservers);

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
        }
Example #5
0
            public void Dispose()
            {
                if (subject.IsCompleted)
                {
                    var disposable = subject.GetResult();
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }

                subject.Dispose();
            }
        internal static IObservable <T> ToAsyncSource <T>(this IObservable <T> source, Duration lifetime, IClock clock)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var gate = new object();
            AsyncSubject <T>?subject    = null;
            IDisposable?     connection = null;

            var updated  = Instant.MinValue;
            var complete = false;

            return(Observable.Create <T>(observer =>
            {
                lock (gate)
                {
                    if (subject == null || ((clock.GetCurrentInstant() - updated > lifetime || !complete) && !subject.HasObservers))
                    {
                        subject?.Dispose();
                        subject = new AsyncSubject <T>();
                        complete = false;
                        updated = clock.GetCurrentInstant();
                        connection?.Dispose();
                        connection = source
                                     .Subscribe(
                            onNext: subject.OnNext,
                            onError: subject.OnError,
                            onCompleted: () =>
                        {
                            lock (gate)
                            {
                                complete = true;
                                subject.OnCompleted();
                            }
                        });
                    }

                    var subscription = subject.Subscribe(observer);

                    return Disposable.Create(() =>
                    {
                        lock (gate)
                            subscription.Dispose();
                    });
                }
            }));
        }
Example #7
0
        /// <summary>
        /// Disposes managed resources that are disposable and handles cleanup of unmanaged items.
        /// </summary>
        /// <param name="isDisposing">If we are disposing managed resources.</param>
        protected virtual void Dispose(bool isDisposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (isDisposing)
            {
                _queuedOps?.Dispose();
                _shutdownObs?.Dispose();
            }

            _isDisposed = true;
        }
Example #8
0
        public void HasObservers_Dispose2()
        {
            var s = new AsyncSubject <int>();

            Assert.IsFalse(s.HasObservers);

            var d = s.Subscribe(_ => { });

            Assert.IsTrue(s.HasObservers);

            d.Dispose();
            Assert.IsFalse(s.HasObservers);

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
        }
Example #9
0
 /// <summary>
 /// クライアントを破棄する
 /// </summary>
 public void Dispose()
 {
     lock (lockObject)
     {
         if (_ws != null)
         {
             _ws.Close();
         }
         if (_disposedEventAsyncSubject != null)
         {
             _disposedEventAsyncSubject.OnNext(Unit.Default);
             _disposedEventAsyncSubject.OnCompleted();
             _disposedEventAsyncSubject.Dispose();
         }
         _ws         = null;
         _isDisposed = true;
     }
 }
Example #10
0
        /// <summary>
        /// Acquires the read or write lock on the scheduler, as observable.
        /// </summary>
        /// <param name="schedulingTaskFactory">The task factory.</param>
        /// <returns></returns>
        private IObservable <ReaderWriterLock> AcquireReadOrWriteLockObservable(TaskFactory schedulingTaskFactory)
        {
            // check for incorrect entry once we have already been disposed
            if (IsDisposed)
            {
                return(Observable.Throw <ReaderWriterLock>(new ObjectDisposedException(this.GetType().Name)));
            }

            // basically what happens here is we use the (concurrent) reader or (exclusive) handed in
            // and schedule a new tpl task on it which merely wraps or contains chained IDisposable creation.
            // What happens then is, we return a 'future' promise or timeslot for whenever the ConcurrentExclusiveSchedulerPair
            // does actually start working on that TPL task (meaning that by its own, internal r/w locking, the task was up next).

            // this is the result we hand back to the caller
            var asyncSubject = new AsyncSubject <ReaderWriterLock>();
            var gate         = new AsyncSubject <Unit>();

            schedulingTaskFactory.StartNew(async() =>
            {
                // this asyncSubject is the one actually handed back to the method's caller as IDisposable instance
                // & whenever that one is disposed, the gate gets unblocked \o/
                asyncSubject.OnNext(
                    new ReaderWriterLock(
                        Interlocked.Increment(ref _scheduledOperationId),
                        schedulingTaskFactory == ExclusiveTaskFactory,
                        Disposable.Create(() =>
                {
                    gate.OnNext(Unit.Default);
                    gate.OnCompleted();
                })));
                asyncSubject.OnCompleted();

                // once the asyncSubject's ticket has been disposed, this gate gets unlocked, too
                await gate;

                // cleanup
                gate.Dispose();
                gate = null;
            });

            return(asyncSubject);
        }
Example #11
0
        protected async Task <bool> HookProgress(AsyncOperation operation, ProgressDelegate progress, float weight = 1.0f)
        {
            var promise    = new AsyncSubject <int>();
            var disposable = Observable.Interval(TimeSpan.FromSeconds(1 / 30f))
                             .Select(x => new ProgressInfo()
            {
                current = x,
                total   = operation.allowSceneActivation ? 1f : 0.9f,
                weight  = weight,
            })
                             .TakeWhile(x =>
            {
                if (x.current < x.total)
                {
                    return(true);
                }
                if (progress != null)
                {
                    progress(x.Percent());
                }
                promise.OnNext(0);
                promise.OnCompleted();
                return(false);
            }).Subscribe(x =>
            {
                if (progress != null)
                {
                    progress(x.Percent());
                }
            });
            await promise;

            promise.Dispose();
            disposable.Dispose();
            return(true);
        }
Example #12
0
    // Update is called once per frame
    void OnDestory()
    {
        _Disposable?.Dispose();

        _OnTimeUpAsyncSubject.Dispose();
    }
Example #13
0
 public void Dispose()
 {
     _shutdownSignal.Dispose();
     GC.SuppressFinalize(this);
 }
		/// <summary>
		/// Acquires the read or write lock on the scheduler, as observable.
		/// </summary>
		/// <param name="schedulingTaskFactory">The task factory.</param>
		/// <returns></returns>
		private IObservable<ReaderWriterLock> AcquireReadOrWriteLockObservable(TaskFactory schedulingTaskFactory)
		{
			// check for incorrect entry once we have already been disposed
			if (IsDisposed)
				return Observable.Throw<ReaderWriterLock>(new ObjectDisposedException(this.GetType().Name));

			// basically what happens here is we use the (concurrent) reader or (exclusive) handed in
			// and schedule a new tpl task on it which merely wraps or contains chained IDisposable creation.
			// What happens then is, we return a 'future' promise or timeslot for whenever the ConcurrentExclusiveSchedulerPair
			// does actually start working on that TPL task (meaning that by its own, internal r/w locking, the task was up next).

			// this is the result we hand back to the caller
			var asyncSubject = new AsyncSubject<ReaderWriterLock>();
			var gate = new AsyncSubject<Unit>();

			schedulingTaskFactory.StartNew(async () =>
			{
				// this asyncSubject is the one actually handed back to the method's caller as IDisposable instance
				// & whenever that one is disposed, the gate gets unblocked \o/
				asyncSubject.OnNext(
					new ReaderWriterLock(
						Interlocked.Increment(ref _scheduledOperationId),
						schedulingTaskFactory == ExclusiveTaskFactory,
						Disposable.Create(() =>
						{
							gate.OnNext(Unit.Default);
							gate.OnCompleted();
						})));
				asyncSubject.OnCompleted();

				// once the asyncSubject's ticket has been disposed, this gate gets unlocked, too
				await gate;

                // cleanup
                gate.Dispose();
			    gate = null;
			});

			return asyncSubject;
		}
Example #15
0
        public void HasObservers_Dispose3()
        {
            var s = new AsyncSubject<int>();
            Assert.IsFalse(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
            Assert.IsTrue(s.IsDisposed);
        }
Example #16
0
 public void Dispose() => subject.Dispose();
Example #17
0
 public bool TrySetCanceled()
 {
     _tcs.Dispose();
     _tcs.OnCompleted();
     return(true);
 }
Example #18
0
 public void Dispose()
 {
     subject.Dispose();
 }
Example #19
0
        public void HasObservers_Dispose2()
        {
            var s = new AsyncSubject<int>();
            Assert.IsFalse(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            var d = s.Subscribe(_ => { });
            Assert.IsTrue(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            d.Dispose();
            Assert.IsFalse(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
            Assert.IsTrue(s.IsDisposed);
        }
Example #20
0
 public void Dispose()
 {
     _subject.Dispose();
     GC.SuppressFinalize(this);
 }
Example #21
0
 void Destroy()
 {
     disposable?.Dispose();
     onTimeUpAsyncSubject.Dispose();
 }
 public void Dispose()
 {
     _asyncSubject.Dispose();
 }