I have read that Async function implicitly return a promise which is resolved by the return. Is there a way to get that promise returned by Async function so that we could resolve it ourself ?
I have a use case where i call an api which accepts a function which will be called asynchronously.
/**
*
* @param {Array} keys - list of keys to get values
*/
let getStorageValues = async (keys) => {
// chrome.storage.sync.get accepts second argument which is called asynchronously.
chrome.storage.sync.get(keys, (values) => {
if (values) {
return values;
} else {
return new Error('throw')
}
})
}
Instead i would want something like
let getStorageValues = async (keys) => {
let AsyncPromise = Async Function Promise.
chrome.storage.sync.get(keys, (values) => {
if (values) {
AsyncPromise.resolve(values);
} else {
AsyncPromise.reject(new Error('throw'))
}
})
}
If i could get access to the Promise returned by Async function i could use that to resolve the values variable used inside chrome.storage.sync.get