diff --git a/lib/client.js b/lib/client.js index 32e25c3..3ab2aff 100644 --- a/lib/client.js +++ b/lib/client.js @@ -556,13 +556,23 @@ export default class Client { options = { url: options } } - this.on(requestKey + '.done', (evt) => { + const doneEventKey = `${requestKey}.done` + const failEventKey = `${requestKey}.fail` + + const doneHandler = (evt) => { resolve.apply(this, evt.responseArgs) - }) + this.off(failEventKey, failHandler) + this.off(doneEventKey, doneHandler) + } - this.on(requestKey + '.fail', (evt) => { + const failHandler = (evt) => { reject.apply(this, evt.responseArgs) - }) + this.off(failEventKey, failHandler) + this.off(doneEventKey, doneHandler) + } + + this.on(doneEventKey, doneHandler) + this.on(failEventKey, failHandler) this.postMessage(requestKey, options) })