async_db: add WriterSink
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-08-13 18:16:49 +03:00
parent 3e3572ce12
commit 31c02ae8ef
2 changed files with 83 additions and 12 deletions

View File

@@ -178,15 +178,11 @@ async fn db_writer_task(rx: UnboundedReceiver<Question>) {
let mut writer: async_db::Writer<Question> =
async_db::Writer::new(NEW_DB_FILENAME, writer_opts)
.await
.expect("new db writer");
let mut stream: UnboundedReceiverStream<_> = rx.into();
writer
.load(&mut stream)
.await
.unwrap_or_else(|e| panic!("db writer load, {e:#?}"));
.unwrap_or_else(|e| panic!("db writer load, {e:#?}"));
let stream: UnboundedReceiverStream<_> = rx.into();
let stream = stream.map(Ok);
stream.forward(writer.sink()).await.expect("forward");
writer.finish().await.expect("db writer finish");
println!("write done");