Ejemplo n.º 1
0
        /// <summary>
        /// Disposes of the instance.
        /// </summary>
        public void Dispose()
        {
            lock (sync)
            {
                if (disposed)
                {
                    return;
                }

                if (attempt != null)
                {
                    attempt.Dispose();
                    attempt = null;
                }

                disposed = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a task that completes when the job is complete.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task <TResult> WaitAsync(CancellationToken cancellationToken = default)
        {
            lock (sync)
            {
                if (disposed)
                {
                    throw new ObjectDisposedException(nameof(AsyncJob <TResult>));
                }

                // entire job was canceled
                cancellationToken.ThrowIfCancellationRequested();

                // initialize attempt
                if (attempt == null)
                {
                    attempt = new AsyncJobAttempt(Work, Exit);
                }

                // subscribe new waiter
                return(attempt.WaitAsync(cancellationToken));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Invoked when the attempt exits early.
 /// </summary>
 void Exit()
 {
     lock (sync)
         attempt = null;
 }