{"action":"created","issue":{"url":"https://api.github.com/repos/nodegit/promisify-node/issues/8","labels_url":"https://api.github.com/repos/nodegit/promisify-node/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/nodegit/promisify-node/issues/8/comments","events_url":"https://api.github.com/repos/nodegit/promisify-node/issues/8/events","html_url":"https://github.com/nodegit/promisify-node/issues/8","id":57164890,"number":8,"title":"Cannot promisify node-serialport","user":{"login":"endorama","id":526307,"avatar_url":"https://avatars.githubusercontent.com/u/526307?v=3","gravatar_id":"","url":"https://api.github.com/users/endorama","html_url":"https://github.com/endorama","followers_url":"https://api.github.com/users/endorama/followers","following_url":"https://api.github.com/users/endorama/following{/other_user}","gists_url":"https://api.github.com/users/endorama/gists{/gist_id}","starred_url":"https://api.github.com/users/endorama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endorama/subscriptions","organizations_url":"https://api.github.com/users/endorama/orgs","repos_url":"https://api.github.com/users/endorama/repos","events_url":"https://api.github.com/users/endorama/events{/privacy}","received_events_url":"https://api.github.com/users/endorama/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-10T11:52:43Z","updated_at":"2015-02-19T16:20:57Z","closed_at":"2015-02-19T16:20:57Z","body":"Hello, I'm trying to use this module bu I'm having some weird time with node-serialport.\r\n\r\nThe problems seems to be the SerialPort constructor, which accepts a callback that is correctly promisified but not resolved ( at least this is what is seems to me ).\r\n\r\n```javascript\r\nvar promisify = require(\"promisify-node\");\r\nvar serialport = promisify('serialport');\r\nvar SerialPort = serialport.SerialPort;\r\n\r\n\r\nvar port = \"/dev/ttyACM0\";\r\nvar serial_port = new SerialPort(port, {\r\n    baudrate: 57600,\r\n    parser: serialport.parsers.readline(\"\\n\")\r\n});\r\n\r\nconsole.log(serial_port)\r\n// Promise {then: function, state: null, isFulfilled: function, isRejected: function, isPending: function…}\r\nserial_port\r\n  .then(function() {console.log(arguments, serial_port)})\r\n  // [undefined] Promise {then: function, state: null, isFulfilled: function, isRejected: function, isPending: function…}\r\n```\r\n\r\nIn this situation I'm not able to call methods on the serial_port object. Any hint on how to solve this? Thanks in advance."},"comment":{"url":"https://api.github.com/repos/nodegit/promisify-node/issues/comments/75081835","html_url":"https://github.com/nodegit/promisify-node/issues/8#issuecomment-75081835","issue_url":"https://api.github.com/repos/nodegit/promisify-node/issues/8","id":75081835,"user":{"login":"maxkorp","id":1302526,"avatar_url":"https://avatars.githubusercontent.com/u/1302526?v=3","gravatar_id":"","url":"https://api.github.com/users/maxkorp","html_url":"https://github.com/maxkorp","followers_url":"https://api.github.com/users/maxkorp/followers","following_url":"https://api.github.com/users/maxkorp/following{/other_user}","gists_url":"https://api.github.com/users/maxkorp/gists{/gist_id}","starred_url":"https://api.github.com/users/maxkorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxkorp/subscriptions","organizations_url":"https://api.github.com/users/maxkorp/orgs","repos_url":"https://api.github.com/users/maxkorp/repos","events_url":"https://api.github.com/users/maxkorp/events{/privacy}","received_events_url":"https://api.github.com/users/maxkorp/received_events","type":"User","site_admin":false},"created_at":"2015-02-19T16:20:57Z","updated_at":"2015-02-19T16:20:57Z","body":"Ah found it. It was pending forever. It turns out that A) You don't need the second promisify (so this should be fine)\r\n```js\r\nvar promisify = require(\"promisify-node\");\r\nvar serialport = promisify('serialport');\r\nvar SerialPort = serialport.SerialPort;\r\n```\r\n\r\nThe issue is that it's only getting 2 arguments in from you, and so it passes the callback for the third, which just gets used as a truthy value, rather than being called as the callback, so you need to pass the argument for openImmediately (the third of four in a typical serialport construction) as whichever you want.\r\n\r\n```js\r\nvar port = \"/dev/ttyACM0\";\r\nvar serial_port = new SerialPort(port, {\r\n    baudrate: 57600,\r\n    parser: serialport.parsers.readline(\"\\n\")\r\n}, \r\ntrue); //this is the important one. \r\n```\r\n\r\nif youd like to be able to skip it, you can roll a custom promise on top\r\n```js\r\nvar promisify = require(\"promisify-node\");\r\nvar serialport = promisify('serialport');\r\nvar SerialPort = function(port, opts, openImmediately) {\r\n  openImmediately = openImmediately || false;\r\n  opts = opts || {};\r\n  return new serialport.SerialPort(port, opts, openImmediately);\r\n};\r\n\r\nvar port = \"/dev/ttyACM0\";\r\nvar serial_port = SerialPort(port, {\r\n    baudrate: 57600,\r\n    parser: serialport.parsers.readline(\"\\n\")\r\n}, true);\r\n```\r\n\r\nRegarding the other methods, it may have tried to promisify `.on`, which either is or works like an event emitter, so that might need custom promisification as well. \r\n\r\nI'm going to make an issue for promisify requiring you to pass in all of the options with constructors, but I'm going to close this now that its figured out. Feel free to post here still though if there's still an issue for you. "}}