{"action":"created","issue":{"url":"https://api.github.com/repos/hunterloftis/jackrabbit/issues/39","labels_url":"https://api.github.com/repos/hunterloftis/jackrabbit/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/hunterloftis/jackrabbit/issues/39/comments","events_url":"https://api.github.com/repos/hunterloftis/jackrabbit/issues/39/events","html_url":"https://github.com/hunterloftis/jackrabbit/issues/39","id":128254817,"number":39,"title":"Expand queue interface...","user":{"login":"tracker1","id":444316,"avatar_url":"https://avatars.githubusercontent.com/u/444316?v=3","gravatar_id":"","url":"https://api.github.com/users/tracker1","html_url":"https://github.com/tracker1","followers_url":"https://api.github.com/users/tracker1/followers","following_url":"https://api.github.com/users/tracker1/following{/other_user}","gists_url":"https://api.github.com/users/tracker1/gists{/gist_id}","starred_url":"https://api.github.com/users/tracker1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tracker1/subscriptions","organizations_url":"https://api.github.com/users/tracker1/orgs","repos_url":"https://api.github.com/users/tracker1/repos","events_url":"https://api.github.com/users/tracker1/events{/privacy}","received_events_url":"https://api.github.com/users/tracker1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-22T21:50:00Z","updated_at":"2016-01-22T22:04:41Z","closed_at":null,"body":"I'd like to suggest two additional methods for rpc calls (When `global.Promise` exists) ...\r\n\r\n```\r\n...\r\nvar queue = exchange.queue({ name: 'rpc_queue', prefetch: 1, durable: false });\r\n\r\n// queue.work returns a promise -- arguments serialized as array\r\nvar request = queue.work(...arguments);\r\n...\r\n// worker accepts a method that returns a promise\r\nqueue.worker(doWork);\r\n\r\nfunction doWork(...arguments) { //arguments spread back\r\n  return Promise...\r\n]\r\n```\r\n\r\n-------\r\n\r\nIt would work best, if the input arguments were all passed through, serialized then deserialzed as an array, in this way, local methods that return a promise can be replaced with rpc calls to do the same interface...  A Promise based workflow would look like:\r\n\r\n```\r\nvar rpc = exchange.queue({ name: 'rpc_queue', prefetch: 1, durable: false });\r\n\r\n...\r\n//client\r\nrpc.work('a', {'some':'object'}).then(\r\n    function(result) {\r\n      //successful result\r\n    },\r\n    function(err) {\r\n      //error either in call, or from remote\r\n    }\r\n);\r\n...\r\n//server\r\nrpc.worker(function(strInput, objinput) {\r\n  return new Promise(function(resolve,reject){\r\n    //do some async work, etc\r\n    return someAsyncWork(strInput)\r\n      .then(moreAsyncWork.bind(null, objinput))\r\n      .then(function(){\r\n        return 'success';\r\n      });\r\n  });\r\n})\r\n```\r\n\r\n-----\r\n\r\nWith the benefit of `async` and `await` support fia Babel or TypeScript:\r\n\r\n```\r\nvar result = rpc.work('a', {'some':'object'});\r\n...\r\nrpc.worker(async function(strinput, objinput) {\r\n  await someAsyncWork(strinput);\r\n  await moreAsyncWork(objinput);\r\n  return 'success';\r\n})\r\n```\r\n\r\n-----\r\n\r\nAs you can see, with the final async example, this simplifies things a *LOT*"},"comment":{"url":"https://api.github.com/repos/hunterloftis/jackrabbit/issues/comments/174067531","html_url":"https://github.com/hunterloftis/jackrabbit/issues/39#issuecomment-174067531","issue_url":"https://api.github.com/repos/hunterloftis/jackrabbit/issues/39","id":174067531,"user":{"login":"tracker1","id":444316,"avatar_url":"https://avatars.githubusercontent.com/u/444316?v=3","gravatar_id":"","url":"https://api.github.com/users/tracker1","html_url":"https://github.com/tracker1","followers_url":"https://api.github.com/users/tracker1/followers","following_url":"https://api.github.com/users/tracker1/following{/other_user}","gists_url":"https://api.github.com/users/tracker1/gists{/gist_id}","starred_url":"https://api.github.com/users/tracker1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tracker1/subscriptions","organizations_url":"https://api.github.com/users/tracker1/orgs","repos_url":"https://api.github.com/users/tracker1/repos","events_url":"https://api.github.com/users/tracker1/events{/privacy}","received_events_url":"https://api.github.com/users/tracker1/received_events","type":"User","site_admin":false},"created_at":"2016-01-22T22:04:41Z","updated_at":"2016-01-22T22:04:41Z","body":"For returning errors, would suggest ensuring the `message` and `stack` properties are included.\r\n\r\n```\r\n// ES6 syntax...\r\nimport stringify from 'json-stringify-safe';\r\n...\r\nfunction successHandler(result) {\r\n  return stringify({response:'resolve',resolve:result});\r\n}\r\n\r\nfunction errorHandler(err) {\r\n  //err.message and stack are inherited properties, they don't serialize normally\r\n  if (err instanceof Error) err = {...err, message:err.message, stack:err.stack};\r\n\r\n  //serialize rejection\r\n  return stringify({response:'reject',reject:err});\r\n}\r\n```"}}