[iso-core] Fix IMAPConnection.openBox

Set _isOpeningBox to true at the right moment
This commit is contained in:
Juan Tejada 2017-03-01 17:19:21 -08:00
parent 606dd6ea4b
commit 0cf6027482

View file

@ -268,6 +268,13 @@ class IMAPConnection extends EventEmitter {
return this._imap.serverSupports(capability);
}
getLastOpenDuration() {
if (this._isOpeningBox) {
throw new RetryableError('IMAPConnection: Cannot operate on connection while opening a box.')
}
return this._lastOpenDuration;
}
/**
* @return {Promise} that resolves to instance of IMAPBox
*/
@ -281,9 +288,9 @@ class IMAPConnection extends EventEmitter {
if (!refetchBoxInfo && folderName === this.getOpenBoxName()) {
return Promise.resolve(new IMAPBox(this, this._imap._box));
}
this._isOpeningBox = true
this._lastOpenDuration = null;
return this._withPreparedConnection(async (imap) => {
this._isOpeningBox = true
this._lastOpenDuration = null;
const before = Date.now();
const box = await imap.openBoxAsync(folderName, readOnly)
this._lastOpenDuration = Date.now() - before;
@ -292,13 +299,6 @@ class IMAPConnection extends EventEmitter {
})
}
getLastOpenDuration() {
if (this._isOpeningBox) {
throw new RetryableError('IMAPConnection: Cannot operate on connection while opening a box.')
}
return this._lastOpenDuration;
}
async getLatestBoxStatus(folderName) {
if (!folderName) {
throw new Error('IMAPConnection::getLatestBoxStatus - You must provide a folder name')