code-corps / ember-stripe-service

An ember-cli addon which injects Stripe as an Ember service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why all the manual run loops?

bf4 opened this issue · comments

in stripe.js you call Ember.run.begin(); and Ember.run.end() and I was wondering why you'd want to do that? Isn't that a bit unusual?

function createCardToken (card) {

  // manually start Ember loop
  Ember.run.begin();

  return new Ember.RSVP.Promise(function (resolve, reject) {
    Stripe.card.createToken(card, function (status, response) {

      if (response.error) {
        reject(response);
        return Ember.run.end();
      }

      resolve(response);

      Ember.run.end();
    });
  });
}


function createBankAccountToken(bankAccount) {

  // manually start Ember loop
  Ember.run.begin();

  return new Ember.RSVP.Promise(function (resolve, reject) {
    Stripe.bankAccount.createToken(bankAccount, function (status, response) {

      if (response.error) {
        reject(response);
        return Ember.run.end();
      }

      resolve(response);

      Ember.run.end();
    });
  });
}

Is there any particular concern other than how unusual it is?

@buritica 1. so sorry I didn't see the other issues. I just looked at pull requests 2. thanks for answering my question! The referenced issues explain it what I was wondering about.

no problem, let us know if you have any issues with this implementation of the run loop, we know it's not ideal :/