Skip to content

Wrapping execution inside a promise freezes #27

@martvaha

Description

@martvaha

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions