Fixed query promises to be able to resolve multiple times

The current implementation of .then does not follow the Promise/A+ spec.

A promise once resolved or rejected should not be able to change its value. The current situation does allow that. For example:

    var promise = query.find({});
    var prevResult;
    promise
      .then(function(result){
        prevResult = result;
        return promise;
      }).then(function(result){
        if (result === prevResult)
          return "the same";
        else
          return "not the same";
      });

This will return "not the same" whereas if "promise" was an actual promise this should return "the same".

Solution: Store the promise in the deferred object and create it only once.