-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
I'm having trouble wrapping connect and exec methods inside a promise. For some reason, the promise is only resolved after the request to the backend has been canceled in the browser.
Environment:
OS: MacOS 10.13.3 / Ubuntu 10.13.3
NodeJS: 8.9.4 / 9.5.0
Steps to reproduce:
npm install express sqlanywhere
const express = require('express');
const sqlanywhere = require('sqlanywhere');
const app = express();
app.get('/', (req, res) => {
const conn = sqlanywhere.createConnection();
const conn_params = {
Host: '****',
UserId: '****',
Password: '****'
};
const promise = new Promise((resolve, reject) => {
conn.connect(conn_params, err => {
if (err) reject(err);
conn.exec('select 1 as test', (err, result) => {
if (err) reject(err);
console.log(result);
resolve(result);
});
});
});
promise.then(data => {
console.log('inside promise.then');
res.json(data);
})
});
app.listen(3000);
process.on('SIGINT', function() {
process.exit();
});node app.js
Open http://localhost:3000/. The result of exec is logged to the console but the response is not sent back to the browser. Also the console.log inside promise.then is logged only after the request has been canceled in the browser.
What am I missing?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels