Skip to content

Commit

Permalink
[Workaround] no longer reject promises while enqueueCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
SunriseFox committed Sep 27, 2018
1 parent 32e768c commit 2e19e9c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ The IMAP client has several events you can attach to by setting a listener
### Handling fatal error event

The invocation of `onerror` indicates an irrecoverable error. When `onerror` is fired, the connection is already closed, hence there's no need for further cleanup.
if no `onerror` callback is set, it will throw the error.

## Get your hands dirty

Expand Down
24 changes: 22 additions & 2 deletions dist/client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/command-parser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/compression.js

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions dist/imap.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/logger.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion res/compression.worker.blob

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export default class Client {
clearTimeout(this._idleTimeout)

// propagate the error upwards
this.onerror && this.onerror(err)
if (!this.onerror) {
throw err
}
this.onerror(err)
}

//
Expand Down
9 changes: 8 additions & 1 deletion src/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export default class Imap {
* @returns {Promise} Resolves when the socket is closed
*/
close (error) {
if (this._enteredClosingState) {
return Promise.resolve()
}
this._enteredClosingState = true
return new Promise((resolve) => {
var tearDown = () => {
// fulfill pending promises
Expand Down Expand Up @@ -257,7 +261,10 @@ export default class Imap {
var tag = 'W' + (++this._tagCounter)
request.tag = tag

return new Promise((resolve, reject) => {
return new Promise(resolve => {
var reject = error => {
return resolve(this.close(error))
}
var data = {
tag: tag,
request: request,
Expand Down

0 comments on commit 2e19e9c

Please sign in to comment.