I don't understand what everyauth promises are.
I see that I need to return a promise object or user, but what is an everyauth promise?
I don't understand what everyauth promises are.
I see that I need to return a promise object or user, but what is an everyauth promise?
It's useful when you have a function that performs authentication, but which does so asynchronously. You can't directly return user information from the function (because you have to wait for the callback to fire), so instead you return a promise. This is a special object that acts as a "placeholder" for what will eventually be filled with user information when the asynchronous request does complete.
Example from the documentation:
function (session, accessToken, extra, oauthUser) {
var promise = this.Promise();
asyncFindUser( function (err, user) {
if (err) return promise.fail(err);
promise.fulfill(user);
});
return promise;
}
It means that the calling context can carry on doing work right up until it really needs that user information (and all the while, in the meantime, the asynchronous request is completing); it would have to wait at that later stage if the user information wasn't yet available. You might think of it as a very specific case of thread creation and joining.
"Promise" is a generic term that covers this sort of functionality in all kinds of languages and contexts:
In computer science, future, promise, and delay refer to constructs used for synchronization in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially not known, usually because the computation of its value has not yet completed.
© 2022 - 2024 — McMap. All rights reserved.