DEV: Prefer Ember's Promise implementation.

approved
#1

DEV: Prefer Ember’s Promise implementation.

diff --git a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6 b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
index b206dc5..80277e9 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
+++ b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
@@ -143,7 +143,7 @@ export default {
           .map(x => x.trim())
           .join("");
 
-        keyPairPromise = Promise.all([
+        keyPairPromise = Ember.RSVP.Promise.all([
           importPublicKey(publicStr),
           importPublicKey(privateStr, ["decrypt", "unwrapKey"])
         ]);
diff --git a/assets/javascripts/discourse/controllers/export-keypair.js.es6 b/assets/javascripts/discourse/controllers/export-keypair.js.es6
index da5478e..040f0d1 100644
--- a/assets/javascripts/discourse/controllers/export-keypair.js.es6
+++ b/assets/javascripts/discourse/controllers/export-keypair.js.es6
@@ -54,7 +54,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
         .then(key => importPrivateKey(privateStr, key, true))
         .then(privateKey => exportPublicKey(privateKey));
 
-      Promise.all([publicStr, exportedPrivateStr])
+      Ember.RSVP.Promise.all([publicStr, exportedPrivateStr])
         .then(([publicKey, privateKey]) => {
           this.setProperties({
             exported: this.packKeyPair(publicKey, privateKey),
diff --git a/test/javascripts/acceptance/encrypt-test.js.es6 b/test/javascripts/acceptance/encrypt-test.js.es6
index c6e8957..17490c3 100644
--- a/test/javascripts/acceptance/encrypt-test.js.es6
+++ b/test/javascripts/acceptance/encrypt-test.js.es6
@@ -120,9 +120,7 @@ async function setEncryptionStatus(status) {
 
 // TODO: Figure out why `await` is not enough.
 function sleep(time) {
-  return new Promise(resolve => {
-    setTimeout(() => resolve(), time);
-  });
+  return new Ember.RSVP.Promise(resolve => setTimeout(resolve, time));
 }
 
 acceptance("Encrypt", {

GitHub sha: cfc8b246

#2

I’m curious: why are Ember’s promises better?

1 Like
Approved #3
#4

The primary reason is that Ember.RSVP.Promise is integrated with Ember’s run-loop while the other implementation is not. There is a really nice article about this on their forum :discourse:

2 Likes