-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37e644d
commit 8c64fdd
Showing
45 changed files
with
454 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,26 @@ | ||
use futures::executor::{block_on, block_on_stream}; | ||
use futures::{channel::mpsc, prelude::*}; | ||
use futures::executor::block_on; | ||
use futures::{channel::mpsc::channel as bounded, prelude::*, sink::unfold}; | ||
use lib::uci::Uci; | ||
use std::io::{prelude::*, stdin, stdout, LineWriter}; | ||
use std::thread; | ||
use std::io::{prelude::*, stdin, stdout}; | ||
use std::{future::ready, thread}; | ||
|
||
fn main() { | ||
let (mut tx, input) = mpsc::channel(32); | ||
let (output, rx) = mpsc::channel(32); | ||
let (mut tx, rx) = bounded(0); | ||
|
||
thread::spawn(move || { | ||
for item in stdin().lock().lines() { | ||
match item { | ||
Err(error) => return eprint!("{error}"), | ||
Ok(line) => { | ||
if let Err(error) = block_on(tx.send(line)) { | ||
if error.is_disconnected() { | ||
break; | ||
} | ||
if block_on(tx.send(line)).is_err() { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
thread::spawn(move || { | ||
let mut stdout = LineWriter::new(stdout().lock()); | ||
for line in block_on_stream(rx) { | ||
if let Err(error) = writeln!(stdout, "{line}") { | ||
return eprint!("{error}"); | ||
} | ||
} | ||
}); | ||
|
||
block_on(Uci::new(input, output).run()).ok(); | ||
let mut stdout = stdout().lock(); | ||
let output = unfold((), |_, line: String| ready(writeln!(stdout, "{line}"))); | ||
block_on(Uci::new(rx, output).run()).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.