feat: Switch from smol runtime to tokio

This commit is contained in:
Michael Aaron Murphy 2022-03-27 17:38:37 +02:00 committed by Michael Murphy
parent 4153f9f060
commit dbfb3921ae
23 changed files with 242 additions and 235 deletions

View file

@ -1,10 +1,12 @@
// Copyright 2021 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use async_process as process;
use futures::{AsyncBufReadExt, AsyncWriteExt, Stream, StreamExt};
use futures::{Stream, StreamExt};
use pop_launcher::{Request, Response};
use std::io;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
use tokio::process;
use tokio_stream::wrappers::LinesStream;
pub struct IpcClient {
pub child: process::Child,
@ -14,8 +16,8 @@ pub struct IpcClient {
impl IpcClient {
pub fn new() -> io::Result<(Self, impl Stream<Item = Response>)> {
let mut child = process::Command::new("pop-launcher")
.stdin(process::Stdio::piped())
.stdout(process::Stdio::piped())
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.spawn()?;
let stdin = child
@ -28,18 +30,17 @@ impl IpcClient {
.take()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "failed to find child stdout"))?;
let responses =
futures::io::BufReader::new(stdout)
.lines()
.filter_map(|result| async move {
if let Ok(line) = result {
if let Ok(event) = serde_json::from_str::<Response>(&line) {
return Some(event);
}
let responses = LinesStream::new(tokio::io::BufReader::new(stdout).lines()).filter_map(
|result| async move {
if let Ok(line) = result {
if let Ok(event) = serde_json::from_str::<Response>(&line) {
return Some(event);
}
}
None
});
None
},
);
let client = Self { child, stdin };
@ -57,6 +58,6 @@ impl IpcClient {
pub async fn exit(mut self) {
let _ = self.send(Request::Exit).await;
let _ = self.child.status().await;
let _ = self.child.wait().await;
}
}