Skip to content

Commit

Permalink
simplify struct Uci
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Nov 9, 2024
1 parent ac27530 commit c3aa484
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 307 deletions.
14 changes: 7 additions & 7 deletions bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use futures::executor::block_on;
use futures::{channel::mpsc::unbounded, sink::unfold};
use futures::{channel::mpsc::unbounded, executor::block_on, sink::unfold as sink};
use lib::uci::Uci;
use std::io::{prelude::*, stdin, stdout};
use std::{future::ready, thread};

fn main() {
let (tx, rx) = unbounded();
let (tx, input) = unbounded();

thread::spawn(move || {
for line in stdin().lock().lines() {
if tx.unbounded_send(line.unwrap()).is_err() {
let mut lines = stdin().lock().lines();
while let Some(Ok(line)) = lines.next() {
if tx.unbounded_send(line).is_err() {
break;
}
}
});

let mut stdout = stdout().lock();
let output = unfold((), |_, line: String| ready(writeln!(stdout, "{line}")));
block_on(Uci::new(rx, output).run()).unwrap();
let output = sink((), |_, line: String| ready(writeln!(stdout, "{line}")));
block_on(Uci::new(input, output).run()).unwrap();
}
Loading

0 comments on commit c3aa484

Please sign in to comment.