javascript - node poller not exiting properly -
I have a function that will select a database X-second. I am using the Q library so that the function promise Could return The function will be used ultimately in the long series. Then () s.
The function gives me the results that I expect, but the results continue to run for 30-40 seconds after coming back. I can not understand why I will not leave after coming back.
var _ = is required ('trash'); Var PG = Requirement ('PG'); Var Q = Expected ('q'); ConnString = 'postgres: // somedb_info'; Var query = "SELECT * job where jobid = 'somejobid123123'"; Export.run_poller = function () {var deferred = Q.defer (); Function exec_query (callback) {pg.connect (connString, function (err, client, done) {if (err) {deferred.reject (err);} client.query (query, function (err, result) {done () ; If (mistake) {deferred back .reject (err);} callback (result. Row [[0]);});}); } Function wait_for (res) {if (res.status == 'COMPLETE') {return deferred.resolve (res); } Other {setTimeout (function () {exec_query (wait_for);}, 1000); }} Exec_query (wait_for); Refund refund. }; To test this, I call the function from the main.js file like this: var poller = require ('./ utils) / Poller ') .run_poller; Polar () Then (console.log). Hold (function (error) {console.log (err, '*');});
Why does not the data disappear after returning to the main junction? Is this a better way to gain?
I think the page has a connection pool, I would have thought it would be sharing some time The resources take time or it just stops for awhile
You may be able to call only process.exit (0)
in your node app, If you know that you are working with all your work
Or, you can find the configuration settings that work on how the connection pool works Receives influences.
On, this is an example that can help:
// Disconnect the client when all query clients will expire. On ('drain', client.end.bind (client));
You should read to make sure that you are using it correctly because in some cases it says that it should not be called (though they are all functioning Can not be applied when done).
Comments
Post a Comment