From afa325244050e7e2839ef958810f6fa13bc470e3 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 9 Jul 2021 00:57:23 -0400 Subject: [PATCH] Fixes #1432: Stops throwing for cancelled promise --- CHANGELOG.md | 1 + src/hovers/hovers.ts | 2 +- src/system/decorators/timeout.ts | 23 ++--------------------- src/views/nodes/contributorsNode.ts | 2 +- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e18d61..45237de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#1432](https://github.com/eamodio/vscode-gitlens/issues/1432) - Unhandled Timeout Promise - Fixes [#1562](https://github.com/eamodio/vscode-gitlens/issues/1562) - Yarn audit fails with 2 high sev vulnerabilities (dev dependencies only) — thanks to [PR #1563](https://github.com/eamodio/vscode-gitlens/pull/1563) by Ivan Volzhev ([@ivolzhevbt](https://github.com/ivolzhevbt)) - Fixes [#1566](https://github.com/eamodio/vscode-gitlens/issues/1566) - Bug: unable to open 'pr.url' when clicking PR link - Fixes [#1545](https://github.com/eamodio/vscode-gitlens/issues/1545) - Missing branch comparison controls in versions 11.5.0 and 11.5.1 diff --git a/src/hovers/hovers.ts b/src/hovers/hovers.ts index 4bf5705..7112c20 100644 --- a/src/hovers/hovers.ts +++ b/src/hovers/hovers.ts @@ -193,7 +193,7 @@ export namespace Hovers { commit.isUncommitted ? commit.getPreviousLineDiffUris(uri, editorLine, uri.sha) : undefined, getAutoLinkedIssuesOrPullRequests(commit.message, remotes), getPullRequestForCommit(commit.ref, remotes), - Container.vsls.maybeGetPresence(commit.email).catch(() => undefined), + Container.vsls.maybeGetPresence(commit.email), ]); const details = await CommitFormatter.fromTemplateAsync(Container.config.hovers.detailsMarkdownFormat, commit, { diff --git a/src/system/decorators/timeout.ts b/src/system/decorators/timeout.ts index 89a21d5..bb0b5f0 100644 --- a/src/system/decorators/timeout.ts +++ b/src/system/decorators/timeout.ts @@ -1,5 +1,5 @@ 'use strict'; -import { CancellationError, is as isPromise } from '../promise'; +import { cancellable, is as isPromise } from '../promise'; export function timeout(timeout: number): any; export function timeout(timeoutFromLastArg: true, defaultTimeout?: number): any; @@ -32,26 +32,7 @@ export function timeout(timeoutOrTimeoutFromLastArg: number | boolean, defaultTi const result = fn?.apply(this, args); if (timeout == null || timeout < 1 || !isPromise(result)) return result; - // const cc = Logger.getCorrelationContext(); - - // const start = process.hrtime(); - - return Promise.race([ - result, - // result.then(r => { - // Logger.debug( - // cc, - // `${GlyphChars.Dash} timed out, but completed after ${Strings.getDurationMilliseconds(start)} ms` - // ); - // return r; - // }), - new Promise((_, reject) => { - const id = setTimeout(() => { - clearTimeout(id); - reject(new CancellationError(result, `Timed out after ${timeout} ms`)); - }, timeout); - }), - ]); + return cancellable(result, timeout, { onDidCancel: resolve => resolve(undefined) }); }; }; } diff --git a/src/views/nodes/contributorsNode.ts b/src/views/nodes/contributorsNode.ts index d4ea06d..ac4a011 100644 --- a/src/views/nodes/contributorsNode.ts +++ b/src/views/nodes/contributorsNode.ts @@ -55,7 +55,7 @@ export class ContributorsNode extends ViewNode undefined); + const presenceMap = await this.maybeGetPresenceMap(contributors); this._children = contributors.map( c => new ContributorNode(this.uri, this.view, this, c, { all: all, ref: ref, presence: presenceMap }),