0

I'm a complete beginner, I have a function 'func' that extract values from sql server, I want to return a promise containing these values when the request complete event is fired, not sure how to accomplish this. Thank you.

function func() {

    const request = new Request('SQL_Procedure');
    request.on('row', (columns) => {
        nums.push(columns[3].value);
    })

    request.on('requestCompleted', () => {
        return new Promise((resolve) => { resolve(nums) })//I want to return nums to the code calling the func() main function.
    });
}
  • "I want to return a promise containing these values when the request complete event is fired," — You can't. You have to return a promise **immediately** and have that promise **resolve** when the complete event fires. – Quentin Dec 27 '21 at 12:03
  • The return in the callback does not return to the outer function – charlietfl Dec 27 '21 at 12:06

0 Answers0