var functions = {
async getWorkList(req) {
const database = req.app.get('database');
try {
const work = await new Promise((resolve, reject) => {
database.WorkModel.list((err, result) => {
if (err) return reject(err);
resolve(result);
})
})
return work
} catch (e) {
throw e
}
}
}
사용
function test() {
functions.getWorkList(req).then((work) => console.log(work))
}
또는
async function test() {
const work = await functions.getWorkList(req)
console.log(work)
}
test()
이렇게 해보세요
async getWorkList(req) {
const database = req.app.get('database');
try {
const work = await new Promise((resolve, reject) => {
database.WorkModel.list((err, result) => {
if (err) return reject(err);
resolve(result);
})
})
return work
} catch (e) {
throw e
}
}
}
사용
function test() {
functions.getWorkList(req).then((work) => console.log(work))
}
또는
async function test() {
const work = await functions.getWorkList(req)
console.log(work)
}
test()
이렇게 해보세요
와 해결했어요! 감사합니다 !!