{"action":"created","issue":{"url":"https://api.github.com/repos/sidorares/node-mysql2/issues/334","repository_url":"https://api.github.com/repos/sidorares/node-mysql2","labels_url":"https://api.github.com/repos/sidorares/node-mysql2/issues/334/labels{/name}","comments_url":"https://api.github.com/repos/sidorares/node-mysql2/issues/334/comments","events_url":"https://api.github.com/repos/sidorares/node-mysql2/issues/334/events","html_url":"https://github.com/sidorares/node-mysql2/issues/334","id":162972625,"number":334,"title":"Wait for all queries to complete?","user":{"login":"mnpenner","id":1112998,"avatar_url":"https://avatars.githubusercontent.com/u/1112998?v=3","gravatar_id":"","url":"https://api.github.com/users/mnpenner","html_url":"https://github.com/mnpenner","followers_url":"https://api.github.com/users/mnpenner/followers","following_url":"https://api.github.com/users/mnpenner/following{/other_user}","gists_url":"https://api.github.com/users/mnpenner/gists{/gist_id}","starred_url":"https://api.github.com/users/mnpenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnpenner/subscriptions","organizations_url":"https://api.github.com/users/mnpenner/orgs","repos_url":"https://api.github.com/users/mnpenner/repos","events_url":"https://api.github.com/users/mnpenner/events{/privacy}","received_events_url":"https://api.github.com/users/mnpenner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-06-29T16:39:59Z","updated_at":"2016-08-15T15:56:01Z","closed_at":null,"body":"I'll start with an example:\r\n\r\n```js\r\nconst mysql = require('mysql2/promise');\r\n\r\nlet pool = mysql.createPool({\r\n\tuser: dbVars.login,\r\n\tpassword: dbVars.password,\r\n\thost: 'dev-sql',\r\n\tconnectionLimit: 10,\r\n\tnamedPlaceholders: true,\r\n});\r\n\r\nlet fullStruct = {\r\n\tserver: {},\r\n\tdatabases: {},\r\n};\r\n\r\npool.query(\"SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) offset\").then(([timeOffsetRows]) => {\r\n\tfullStruct.server.timeOffset = timeOffsetRows[0].offset;\r\n});\r\n\r\n\r\npool.query(\"SELECT IF(@@session.time_zone = 'SYSTEM', @@system_time_zone, @@session.time_zone) timeZone\").then(([timeZoneRows]) => {\r\n\tfullStruct.server.timeZone = timeZoneRows[0].timeZone;\r\n});\r\n\r\nawait pool.end();\r\nconsole.log(fullStruct);\r\n```\r\n\r\nThis results in an error:\r\n\r\n> Error: Pool is closed.\r\n\r\nI believe this happens because I'm closing the pool/connection before one of the queries has started. Now I can fix this by pushing each of those query promises into an array and then calling `Promise.all` before `pool.end`, but littering my code with `queries.push(...)` is kind of gross. \r\n\r\nDoes mysql2 not track the queries internally? Is there no way for me to just say \"wait for everything to complete before closing\"?\r\n"},"comment":{"url":"https://api.github.com/repos/sidorares/node-mysql2/issues/comments/239842872","html_url":"https://github.com/sidorares/node-mysql2/issues/334#issuecomment-239842872","issue_url":"https://api.github.com/repos/sidorares/node-mysql2/issues/334","id":239842872,"user":{"login":"sidorares","id":173025,"avatar_url":"https://avatars.githubusercontent.com/u/173025?v=3","gravatar_id":"","url":"https://api.github.com/users/sidorares","html_url":"https://github.com/sidorares","followers_url":"https://api.github.com/users/sidorares/followers","following_url":"https://api.github.com/users/sidorares/following{/other_user}","gists_url":"https://api.github.com/users/sidorares/gists{/gist_id}","starred_url":"https://api.github.com/users/sidorares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sidorares/subscriptions","organizations_url":"https://api.github.com/users/sidorares/orgs","repos_url":"https://api.github.com/users/sidorares/repos","events_url":"https://api.github.com/users/sidorares/events{/privacy}","received_events_url":"https://api.github.com/users/sidorares/received_events","type":"User","site_admin":false},"created_at":"2016-08-15T15:56:01Z","updated_at":"2016-08-15T15:56:01Z","body":"@mnpenner I suspect this has been fixed recently. Do you still have the code around to try?"}}
{"actor":{"display_login":"sidorares"}}