Is there any way a non async function can return the resolved Promise value? Or for async to return non Promise?
I have a module A that I want to import dynamically in module B. Since it's dynamical it produces a promise. From module B I would like to expose part of it (the resolved part of adapterPromise
) as a non Promise object.
const foo = async () => {
return await adapterPromise;
};
export const MyAdapter = () => foo(); // I don't want this to be a Promise
The problem I run into is that since foo
is async, then it always produces a Promise
and I'd like to avoid that (the reason is that MyAdapter
consists of functions that I want to call repeatedly and as far as I know, the same Promise shouldn't be resolved multiple times).
It is possible to do this with Top level await
export default await adapterPromise;
I'm curious if this is the only way.