These are chat archives for Automattic/mongoose

5th
Aug 2018
Mikołaj Chodorowski
@i-Clyde
Aug 05 2018 22:08

Hey!

  // Check if user exist
  function checkUsernameExist(username) {

    do {
      console.log('a0');
      var r=false;function setVal(x) {r=x};
      console.log('a1');
      function done() {
        console.log('done');
      };

      Player.countDocuments({login: username}, function(err, n) {
        console.log('a2');
        if (err) {
          console.log('a3');
          setVal(false);
        } else {
          console.log('a4');
          if (n > 0) setVal(true); else setVal(false);
          return done();
        }
      });
    } while (false);

    console.log('a5');
    return r + console.log(r);
  }

I really hate async since this. How can I make it sync :x