{"action":"created","issue":{"url":"https://api.github.com/repos/vapor/engine/issues/232","repository_url":"https://api.github.com/repos/vapor/engine","labels_url":"https://api.github.com/repos/vapor/engine/issues/232/labels{/name}","comments_url":"https://api.github.com/repos/vapor/engine/issues/232/comments","events_url":"https://api.github.com/repos/vapor/engine/issues/232/events","html_url":"https://github.com/vapor/engine/pull/232","id":298105968,"number":232,"title":"Adds `future.send(to: Websocket)`","user":{"login":"twof","id":5561501,"avatar_url":"https://avatars2.githubusercontent.com/u/5561501?v=4","gravatar_id":"","url":"https://api.github.com/users/twof","html_url":"https://github.com/twof","followers_url":"https://api.github.com/users/twof/followers","following_url":"https://api.github.com/users/twof/following{/other_user}","gists_url":"https://api.github.com/users/twof/gists{/gist_id}","starred_url":"https://api.github.com/users/twof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twof/subscriptions","organizations_url":"https://api.github.com/users/twof/orgs","repos_url":"https://api.github.com/users/twof/repos","events_url":"https://api.github.com/users/twof/events{/privacy}","received_events_url":"https://api.github.com/users/twof/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-18T18:25:13Z","updated_at":"2018-02-19T06:39:15Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/vapor/engine/pulls/232","html_url":"https://github.com/vapor/engine/pull/232","diff_url":"https://github.com/vapor/engine/pull/232.diff","patch_url":"https://github.com/vapor/engine/pull/232.patch"},"body":"Should ease the integration of Websockets into promise chains. Websockets don't mesh well with futures in general right now, but these convenience functions ought to help a bit.\r\n\r\nExample usage:\r\n```\r\nrouter.websocket(\"message\") { (req, websocket) in\r\n    websocket.onString { (ws, msg) in\r\n        let decoder = JSONDecoder()\r\n        let encoder = JSONEncoder()\r\n        let message = try decoder.decode(Message.self, from: msg.data(using: .utf8)!)\r\n        \r\n        req.withPooledConnection(to: .psql, closure: { (conn) in\r\n            return conn\r\n                .query(Message.self)\r\n                .save(message)\r\n                .flatMap(to: [Message].self) { (_) -> Future<[Message]> in\r\n                    return conn.query(Message.self).all()\r\n                }.map(to: String.self) { (allMessages) in\r\n                    guard let allJSONMessages = try encoder.encode(allMessages).toString()\r\n                        else {throw Abort(.internalServerError)}\r\n                    return allJSONMessages\r\n                }.send(to: ws) // This is the addition\r\n                .catch({ (err) in\r\n                    print(err)\r\n                })\r\n        })\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/vapor/engine/issues/comments/366600710","html_url":"https://github.com/vapor/engine/pull/232#issuecomment-366600710","issue_url":"https://api.github.com/repos/vapor/engine/issues/232","id":366600710,"user":{"login":"twof","id":5561501,"avatar_url":"https://avatars2.githubusercontent.com/u/5561501?v=4","gravatar_id":"","url":"https://api.github.com/users/twof","html_url":"https://github.com/twof","followers_url":"https://api.github.com/users/twof/followers","following_url":"https://api.github.com/users/twof/following{/other_user}","gists_url":"https://api.github.com/users/twof/gists{/gist_id}","starred_url":"https://api.github.com/users/twof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twof/subscriptions","organizations_url":"https://api.github.com/users/twof/orgs","repos_url":"https://api.github.com/users/twof/repos","events_url":"https://api.github.com/users/twof/events{/privacy}","received_events_url":"https://api.github.com/users/twof/received_events","type":"User","site_admin":false},"created_at":"2018-02-19T06:39:14Z","updated_at":"2018-02-19T06:39:14Z","author_association":"NONE","body":"Oh yeah that might be better. It would also be nice if you could send Content via a websocket and have it converted to JSON automatically like you can via HTTP. I don't know if that's bad practice or anything though."}}
{"actor":{"display_login":"twof"}}