Imagine having this block of code:
const myFunction = async => {
const result = await foobar()
}
const foobar = async () => {
const result = {}
result.foo = await foo()
result.bar = await bar()
return result
}
Now, let's transform it to:
const myFunction = () => {
const result = foobar()
}
Attempted to modify foobar using the following:
const foobar = async () => {
return (async () => {
const result = {}
result.foo = await foo()
result.bar = await bar()
return result
})()
}
However, this approach still yields a promise
It is not possible to use .then in myFunction, as it is necessary for foobar to return the result variable instead of a promise.
The issue arises from myFunction being an async function, resulting in a promise return, while the desired outcome is to obtain undefine by eliminating async from myFunction.
Update: per Sebastian Speitel's suggestion, the intent is to convert myFunction to synchronous.
Update 2: addressing Shilly's comment, the context involves using nightwatch for end-to-end testing. If myFunction() encounters an error during execution, the virtual machines in nightwatch will continue running indefinitely instead of stopping. This behavior is attributed to the async nature of the invoked function.