I just want to wait for a process to finish, not want to make the function asynchronous.
See the below code.
I had to make getUserList asynchronous because there was an await keyword in the function. Therefore I also had to write like "await UsersService.getUserList" to execute the method and also I had to make the parent function asynchronous. That's not what I want to do.
import xr from 'xr' //a package for http requests
class UsersService {
static async getUserList() {
const res = await xr.get('http://localhost/api/users')
return res.data
}
}
export default UsersService
import UsersService from './UsersService'
class SomeClass {
async someFunction() { //async again!!
const users = await UsersService.getUserList() //await again!!
}
}
async
the function is synchronous, hence - it's guaranteed to complete its body execution and return result.//await again!!
--- sure, if it's asynchronous, you need to wait while it completes.