She's a bird.



  • There's been some misunderstanding in the promis. Main function a() and function b()where the database is approached. After function b()The result should be transferred to a() for further processing. But I understand, resolve( b(user) ) Called before it worked. b()♪ How can we solve the problem?

    function a(){
    
    var info = {email: 'email@email.ru'},
        user = new Promise(function(resolve, reject) {
          resolve( b(user) );
        });
    
    user.then(function(result) {
    
     res.send( result );
    });
    

    }

    function b(params){

    model.user.findAll({
    
        where:{ email: params['email'] }
    
    }).then(function(user){
    
        return(user);
    });
    

    }



  • function b The Promise can be returned if you add return, so there is no need to create it. a

    function a(){
    
    var info = {email: 'email@email.ru'},
        user = b(info);
    
    user.then(function(result) {
        res.send( result );
    });
    

    }

    function b(params){

    return model.user.findAll({
    
        where:{ email: params['email'] }
    
    }).then(function(user){
    
        return(user);
    });
    

    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2