示例#1
0
        protected async Task <T> RunServiceAsync <T>(Func <Task <T> > callAsync, CancellationToken cancellationToken, [CallerMemberName] string?callerName = null)
        {
            AssetStorage.UpdateLastActivityTime();

            try
            {
                return(await callAsync().ConfigureAwait(false));
            }
            catch (Exception ex) when(EndPoint.ReportAndPropagateUnexpectedException(ex, cancellationToken, callerName))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
示例#2
0
        protected async Task <T> RunServiceAsync <T>(Func <Task <T> > callAsync, CancellationToken cancellationToken)
        {
            AssetStorage.UpdateLastActivityTime();

            try
            {
                return(await callAsync().ConfigureAwait(false));
            }
            catch (Exception ex) when(FatalError.ReportWithoutCrashUnlessCanceledAndPropagate(ex, cancellationToken))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
示例#3
0
        protected async Task <T> RunServiceAsync <T>(Func <Task <T> > callAsync, CancellationToken cancellationToken)
        {
            AssetStorage.UpdateLastActivityTime();

            try
            {
                return(await callAsync().ConfigureAwait(false));
            }
            catch (Exception ex) when(LogUnlessCanceled(ex, cancellationToken))
            {
                // never reach
                return(default(T));
            }
        }
        protected async Task <T> RunServiceAsync <T>(Func <CancellationToken, Task <T> > callAsync, CancellationToken cancellationToken)
        {
            AssetStorage.UpdateLastActivityTime();

            // merge given cancellation token with shutdown cancellation token. it looks like if cancellation and disconnection happens
            // almost same time, we might not get cancellation message back from stream json rpc and get disconnected
            // https://github.com/Microsoft/vs-streamjsonrpc/issues/64
            using (var mergedCancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, ShutdownCancellationToken))
            {
                try
                {
                    return(await callAsync(mergedCancellation.Token).ConfigureAwait(false));
                }
                catch (Exception ex) when(LogUnlessCanceled(ex, mergedCancellation.Token))
                {
                    // never reach
                    throw ExceptionUtilities.Unreachable;
                }
            }
        }