Skip to content

Commit

Permalink
Fix program not exiting due to stdin receiver thread
Browse files Browse the repository at this point in the history
  • Loading branch information
the-Jamz committed Jun 8, 2020
1 parent 7466be2 commit 6f5c392
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use crate::error;
use crate::output;

pub async fn receiver(sender: UnboundedSender<String>) {
pub fn receiver(sender: UnboundedSender<String>) {
loop {
let mut input = String::new();
if io::stdin().read_line(&mut input).is_ok() {
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serialport::prelude::*;
use std::env;
use std::time::Duration;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::runtime::Runtime;

#[macro_use]
mod input;
Expand Down Expand Up @@ -40,7 +41,8 @@ fn parse_args() -> Arguments {

async fn monitor(auto: bool, out: &output::Preferences) {
let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel();
tokio::spawn(input::receiver(sender));

std::thread::spawn(|| { input::receiver(sender) });

let settings = tokio_serial::SerialPortSettings {
baud_rate: 115200,
Expand Down

0 comments on commit 6f5c392

Please sign in to comment.