Skip to content

Commit f03b4b1

Browse files
committed
Send messages all at once
1 parent d27518b commit f03b4b1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

postgres-tokio/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,14 @@ impl Connection {
350350
.and_then(|()| frontend::describe(b'S', name, &mut describe))
351351
.and_then(|()| Ok(frontend::sync(&mut sync)))
352352
.into_future()
353-
.and_then(move |()| self.0.send(parse))
354-
.and_then(|s| s.send(describe))
355-
.and_then(|s| s.send(sync))
356-
.and_then(|s| s.flush())
357-
.and_then(|s| s.read())
353+
.and_then(move |()| {
354+
let it = Some(parse).into_iter()
355+
.chain(Some(describe))
356+
.chain(Some(sync))
357+
.map(Ok::<_, io::Error>);
358+
self.0.send_all(futures::stream::iter(it))
359+
})
360+
.and_then(|s| s.0.read())
358361
.map_err(Error::Io)
359362
.boxed() // work around nonlinear trans blowup
360363
.and_then(|(m, s)| {
@@ -484,11 +487,14 @@ impl Connection {
484487
s
485488
})
486489
.into_future()
487-
.and_then(|s| s.0.send(bind).map_err(Error::Io))
488-
.and_then(|s| s.send(execute).map_err(Error::Io))
489-
.and_then(|s| s.send(sync).map_err(Error::Io))
490-
.and_then(|s| s.flush().map_err(Error::Io))
491-
.and_then(|s| s.read().map_err(Error::Io))
490+
.and_then(|s| {
491+
let it = Some(bind).into_iter()
492+
.chain(Some(execute))
493+
.chain(Some(sync))
494+
.map(Ok::<_, io::Error>);
495+
s.0.send_all(futures::stream::iter(it)).map_err(Error::Io)
496+
})
497+
.and_then(|s| s.0.read().map_err(Error::Io))
492498
.and_then(|(m, s)| {
493499
match m {
494500
backend::Message::BindComplete => Either::A(Ok(Connection(s)).into_future()),

0 commit comments

Comments
 (0)