Skip to content

Commit 4e2a64a

Browse files
author
Fabrizio Mirabito
committed
deferred function rewrote as an ES6 class
1 parent d63b22a commit 4e2a64a

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

src/readMessages.js

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,34 +189,16 @@ const parseMessage = message => {
189189
}
190190
};
191191

192-
// Stolen from https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Deferred
193-
function Deferred() {
194-
/* A method to resolve the associated Promise with the value passed.
195-
* If the promise is already settled it does nothing.
196-
*
197-
* @param {anything} value : This value is used to resolve the promise
198-
* If the value is a Promise then the associated promise assumes the state
199-
* of Promise passed as value.
200-
*/
201-
this.resolve = null;
202-
203-
/* A method to reject the assocaited Promise with the value passed.
204-
* If the promise is already settled it does nothing.
205-
*
206-
* @param {anything} reason: The reason for the rejection of the Promise.
207-
* Generally its an Error object. If however a Promise is passed, then the Promise
208-
* itself will be the reason for rejection no matter the state of the Promise.
209-
*/
210-
this.reject = null;
211-
212-
/* A newly created Promise object.
213-
* Initially in pending state.
214-
*/
215-
this.promise = new Promise((resolve, reject) => {
216-
this.resolve = resolve;
217-
this.reject = reject;
218-
});
219-
192+
// Deferred class maps the old way for declaring promises
193+
class Deferred {
194+
constructor() {
195+
this.resolve = null;
196+
this.reject = null;
197+
this.promise = new Promise((resolve, reject) => {
198+
this.resolve = resolve;
199+
this.reject = reject;
200+
});
201+
}
220202
}
221203

222204
const perform = (action, data, cb) => {

0 commit comments

Comments
 (0)