Setting a promise as a variable and using it later
<p>I want to assign a promise to a variable in the following way:</p>

<pre><code>const createSingleUser = function createSingleUser(userData) {
  return new Promise((resolve, reject) =&gt; {
    new User(userData)
    .save()
    .then((user) =&gt; {
      resolve(user, 'user');
    })
    .catch((error) =&gt; {
      reject(error);
    });
  });
};

let createUsers;
if (users instanceof Array) {
  // If we have an array, we're batch creating users
  createUsers = new User().createBatchUsers(users); // returns promise
} else {
  // If we have a single object, we're only creating one user
  createUsers = new User().createSingleUser(users); // returns promise
}
createSingleUser(users)
createUser
.then((result) =&gt; {
.....
</code></pre>

<p>However this does not work due to timing issues. Is there another way to make such a construct without having to write the promise chain twice?</p>

<p><strong>Edit</strong> As @torazaburo mentions, If you create a promise, it will start running. You can assign it to a variable, but the variable will represent the running promise. This is the problem I'm facing. This is the case since createSingleUser is a (Promise) object and not a function.</p>