From 60afd59edcd76a3cd5349689c41e66dff12f0b88 Mon Sep 17 00:00:00 2001 From: joshaber Date: Mon, 11 Jan 2016 15:16:26 -0500 Subject: [PATCH] Serialize refreshing. --- src/git-repository-async.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 9bc5c5999..98725c889 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -43,6 +43,7 @@ export default class GitRepositoryAsync { this.submodules = {} this._refreshingCount = 0 + this._refreshingPromise = Promise.resolve() let {refreshOnWindowFocus = true} = options if (refreshOnWindowFocus) { @@ -896,18 +897,21 @@ export default class GitRepositoryAsync { const branch = this._refreshBranch() const aheadBehind = branch.then(branchName => this._refreshAheadBehindCount(branchName)) - return Promise.all([status, branch, aheadBehind]) - .then(_ => null) - // Because all these refresh steps happen asynchronously, it's entirely - // possible the repository was destroyed while we were working. In which - // case we should just swallow the error. - .catch(e => { - if (this._isDestroyed()) { - return null - } else { - return Promise.reject(e) - } - }) + this._refreshingPromise = this._refreshingPromise.then(_ => { + return Promise.all([status, branch, aheadBehind]) + .then(_ => null) + // Because all these refresh steps happen asynchronously, it's entirely + // possible the repository was destroyed while we were working. In which + // case we should just swallow the error. + .catch(e => { + if (this._isDestroyed()) { + return null + } else { + return Promise.reject(e) + } + }) + }) + return this._refreshingPromise } // Get the submodule for the given path.