forked from
microcosm.blue/microcosm-rs
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
1use anyhow::{bail, Result};
2use std::fs::File;
3use std::io::{self, BufRead};
4use std::path::PathBuf;
5use tinyjson::JsonValue;
6
7pub fn consume_jsonl_file(f: PathBuf, sender: flume::Sender<JsonValue>) -> Result<()> {
8 let file = File::open(f)?;
9 for line in io::BufReader::new(file).lines().map_while(Result::ok) {
10 if let Err(flume::SendError(_rejected)) = sender.send(line.parse()?) {
11 if sender.is_disconnected() {
12 bail!("fixture: send channel disconnected -- nothing to do, bye.");
13 }
14 eprintln!("fixture: failed to send on channel, dropping update! (FIXME / HANDLEME)");
15 }
16 }
17 println!("reached end of jsonl file");
18 Ok(())
19}