関数を非同期にしたくなく、プロセスが終了するのを待ちたいだけです。
以下のコードを参照してください。
関数に await キーワードがあったため、getUserList を非同期にする必要がありました。したがって、メソッドを実行するには「await UsersService.getUserList」のように記述し、親関数を非同期にする必要もありました。それは私がやりたいことではありません。
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!!
}
}