title: How do I return the result from promise to map function
body: <p>I have a javascript promise where I want to return the value to map function that  Easier to see than explain the problem with second promise. I know I can not return value from inside of promise but i ask if there any better solution to that. Thanks</p>
  
  <p>My code:</p>
  
  <pre><code>const _                 = require('lodash')
      Boom                = require('boom'),
      When                = require('when'),
      User                = require('../../models/user');
  
  var users;
  /**
   * Contact core functionality
   */
  users = {
  
  
      /**
       * Find user by id
       *
       * @param       {id} user id
       * @returns     {Promise(User)} User
       */
      findById: (id) =&gt; {
          if (_.isEmpty(id)) {
              return When.reject(Boom.badRequest('User id missing.'))
          }
          return User.get(id).run().then( (user) =&gt; {
              if (user) {
                  return When.resolve(user)
              }
              return When.reject(Boom.notFound('No user registered with provided id.'))
          }).error((error) =&gt; {
              return When.reject(error)
          });
      },
  
      /**
       * Returns all contacts of user from database
       * @returns     [{Promise(Contact)}] contacts
       */
      findContacts: (userId) =&gt; {
          if (_.isEmpty(userId)) {
              return When.reject(Boom.badRequest('User id missing.'))
          }
          return User.get(userId).run().then( (user) =&gt; {
              if (user) {
                  if(_.isObject(user.contacts)){
                      user.contacts = _.map(user.contacts, (contact) =&gt; {
                          this.findById.then((user) =&gt; {
                              contact.user = user
                          })
                          return contact
                      })
                      return When.resolve(user.contacts)
                  }
                  return When.reject(Boom.notFound('No contacts registered with provided user.'));
              }
          }).error((error) =&gt; {
              return When.reject(error)
          })
      },
  }
  </code></pre>
  
  <p>And the issue here:</p>
  
  <pre><code>                user.contacts = _map(user.contacts, (contact) =&gt; {
                      this.findById.then((user) =&gt; {
                          contact.user = user
                      })
                      return contact
                  })
  </code></pre>