Skip to content

Commit 0d3cb0c

Browse files
committed
polish + timing test
1 parent 20461fe commit 0d3cb0c

File tree

3 files changed

+239
-176
lines changed

3 files changed

+239
-176
lines changed

examples/warp_subscriptions/src/main.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ fn schema() -> Schema {
134134
Schema::new(Query, EmptyMutation::new(), Subscription)
135135
}
136136

137-
async fn on_upgrade(ws: warp::ws::WebSocket, root_node: Arc<Schema>) {
138-
serve_graphql_ws(ws, root_node, ConnectionConfig::new(Context {}))
139-
.map(|r| {
140-
if let Err(e) = r {
141-
println!("Websocket error: {}", e);
142-
}
143-
}).await;
144-
}
145-
146137
#[tokio::main]
147138
async fn main() {
148139
env::set_var("RUST_LOG", "warp_subscriptions");
@@ -166,12 +157,18 @@ async fn main() {
166157

167158
let routes = (warp::path("subscriptions")
168159
.and(warp::ws())
169-
.map(
170-
move |ws: warp::ws::Ws| {
171-
let root_node = root_node.clone();
172-
ws.on_upgrade(move |websocket| on_upgrade(websocket, root_node.clone()))
173-
},
174-
))
160+
.map(move |ws: warp::ws::Ws| {
161+
let root_node = root_node.clone();
162+
ws.on_upgrade(move |websocket| async move {
163+
serve_graphql_ws(websocket, root_node, ConnectionConfig::new(Context {}))
164+
.map(|r| {
165+
if let Err(e) = r {
166+
println!("Websocket error: {}", e);
167+
}
168+
})
169+
.await
170+
})
171+
}))
175172
.map(|reply| {
176173
// TODO#584: remove this workaround
177174
warp::reply::with_header(reply, "Sec-WebSocket-Protocol", "graphql-ws")

0 commit comments

Comments
 (0)