Then why does this work? Isn't the whole point of promises to ensure that a task has been completed before moving onto the next task. If the task has already been completed then it just preforms the next task. The promise has an internal state that determines whether the promise was fulfilled.

We only want to index one time, and subsequent searches need to ensure that indexing is complete before preforming a search and "wait" if the indexing is not complete yet. A wrapper with a flag would be redundant.

Unless I'm really misunderstanding what you're saying.

```
/* Output:
I promise to my best
hey man
wazup
*/
   promise = new Promise(function(resolve, reject) {
        console.log("I promise to do my best");
        resolve();
    });

    promise.then(function() {
        console.log("hey man");
    })

    promise.then(function() {
        console.log("wazup");
    })
```