Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is fully-fledged promise

I was going through the mongoose docs when I Stumbled upon the line saying

Mongoose queries are not promises. They have a .then() function for co and async/await as a convenience. If you need a fully-fledged promise, use the .exec() function.

With this example

var query = Band.findOne({name: "Guns N' Roses"});
assert.ok(!(query instanceof Promise));

// A query is not a fully-fledged promise, but it does have a `.then()`.
query.then(function (doc) {
  // use doc
});

// `.exec()` gives you a fully-fledged promise
var promise = query.exec();
assert.ok(promise instanceof Promise);

promise.then(function (doc) {
  // use doc
});

Now, I didn't get what they meant when they said fully-fledge promise, like for me .then() should be a promoise and then it also allows async and await.

So can someone please explain me what does fully-fledge promise mean?

Reference link: https://mongoosejs.com/docs/promises.html#queries-are-not-promises

like image 694
iRohitBhatia Avatar asked Nov 25 '18 17:11

iRohitBhatia


People also ask

What is promise in mongoose?

Built-in Promises This means that you can do things like MyModel. findOne({}). then() and await MyModel. findOne({}). exec() if you're using async/await.

What is a Thenable promise?

“promise” is an object or function with a then method whose behavior conforms to this specification. “thenable” is an object or function that defines a then method.

What is await in mongoose?

Async/await lets us write asynchronous code as if it were synchronous. This is especially helpful for avoiding callback hell when executing multiple async operations in sequence--a common scenario when working with Mongoose.


1 Answers

That means that the values returned by queries are thenables per the definition of the Promises/A+ spec, but not actual Promise instances. That means they may not have all of the features of promises (for instance, catch and finally methods). Actual Promise instances would be "fully-fledged" promises.

The English term "fully-fledged" means "complete" or "fully developed." It comes from ornithology (or at least, terminology related to birds): A chick (a young bird) that has its adult feathers is "fledged;" if it has all its adult feathers completely covering its down undercoat, it's fully-fledged.

like image 64
T.J. Crowder Avatar answered Oct 19 '22 04:10

T.J. Crowder