Anything returned from an async functions comes out as a promise.
For example:
async getDate() {
return new Date();
}
will return a promise with the contents of a date.
An example of reading this overly complicated getDate() function would be:
getDate().then(date => {
console.log("The date: ", date);
});
However, you can also return a promise. This makes your code above perfectly valid, except you don't need to include the await in the return.
You can "simply" just say
return concat(
imageRef.put(image.image).snapshotChanges().pipe(ignoreElements()),
defer(() => imageRef.getDownloadURL())
).pipe(
map(url => {
return {...image, url}
})
).toPromise();
Side note: I am not certain, but I think you should return the object in the map. Changing {...image, url} to return {...image, url}
Additional response:
To retrieve the contents of a promise, use the .then() method. Example:
myReturnedPromise.then(dataOfMyReturnedPromise => {
//This code is called after the promise is resolved.
console.log("The returned value is: ", dataOfMyReturnedPromise);
}).catch(error => {
//If this code is called, the promise completed with an error
//This might be executed if you're retreiving data from the internet
//and your internet connection is too poor to get the data
console.error("Error: ", error);
});
If this answered your question, please mark it as the accepted answer.
asyncit will always return a promise value! You don't technically need thereturn awaitand you could defer theawaitto the callee ofpushImageasync awaitat all. Just return the result. Also, whatever you return from an async function is always a Promise.asyncto useawait... but since your only promise is the last statement, you don't need to useasync/awaitfor that function, the result will always be a Promise anyway - i.e. if there's only ONE promise, and it's the thing that is being returned, there's no need to await .... so there's no need for async