Browse Source

Use futures_util

master
Adrian Heine 3 years ago
parent
commit
aa5b6fa603
  1. 2
      Cargo.toml
  2. 6
      src/async_utils.rs
  3. 6
      src/command_runner.rs
  4. 3
      src/setup/setup.rs
  5. 3
      src/symbols/git/checkout.rs

2
Cargo.toml

@ -8,7 +8,7 @@ build = "src/build.rs"
[dependencies] [dependencies]
users = "0.11.0" users = "0.11.0"
regex = "1.0.1" regex = "1.0.1"
futures = "0.3"
futures-util = "0.3"
async-trait = "0.1" async-trait = "0.1"
tokio = { version = "1.6.1", features = ["rt", "process", "io-util", "macros", "sync"] } tokio = { version = "1.6.1", features = ["rt", "process", "io-util", "macros", "sync"] }
once_cell = "1.4" once_cell = "1.4"

6
src/async_utils.rs

@ -71,7 +71,7 @@ pub fn sleep(duration: Duration) -> impl Future<Output = ()> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::async_utils::{run, sleep}; use crate::async_utils::{run, sleep};
use futures::future::FutureExt;
use futures_util::future::FutureExt;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
#[test] #[test]
@ -80,9 +80,9 @@ mod test {
let start = Instant::now(); let start = Instant::now();
let sleep = sleep(Duration::from_millis(100)).fuse(); let sleep = sleep(Duration::from_millis(100)).fuse();
let ok = async {}.fuse(); let ok = async {}.fuse();
futures::pin_mut!(sleep, ok);
futures_util::pin_mut!(sleep, ok);
loop { loop {
futures::select! {
futures_util::select! {
_ = sleep => {}, _ = sleep => {},
_ = ok => assert!((Instant::now() - start).as_millis() < 100), _ = ok => assert!((Instant::now() - start).as_millis() < 100),
complete => break, complete => break,

6
src/command_runner.rs

@ -192,7 +192,7 @@ mod test {
use crate::args; use crate::args;
use crate::async_utils::run; use crate::async_utils::run;
use crate::command_runner::{CommandRunner, StdCommandRunner}; use crate::command_runner::{CommandRunner, StdCommandRunner};
use futures::future::FutureExt;
use futures_util::future::FutureExt;
use std::time::Instant; use std::time::Instant;
#[test] #[test]
@ -203,9 +203,9 @@ mod test {
let start = Instant::now(); let start = Instant::now();
let res = c.run("sleep", args, "").fuse(); let res = c.run("sleep", args, "").fuse();
let ps = c.run("ps", args![], "").fuse(); let ps = c.run("ps", args![], "").fuse();
futures::pin_mut!(res, ps);
futures_util::pin_mut!(res, ps);
loop { loop {
futures::select! {
futures_util::select! {
_ = res => {}, _ = res => {},
_ = ps => assert!((Instant::now() - start).as_millis() < 1000), _ = ps => assert!((Instant::now() - start).as_millis() < 1000),
complete => break, complete => break,

3
src/setup/setup.rs

@ -6,8 +6,7 @@ use crate::async_utils::sleep;
use crate::loggers::{Logger, StoringLogger}; use crate::loggers::{Logger, StoringLogger};
use crate::resources::{DefaultArtifacts, DefaultResources, FromArtifact, FromResource}; use crate::resources::{DefaultArtifacts, DefaultResources, FromArtifact, FromResource};
use crate::{DefaultBuilder, DefaultLocator}; use crate::{DefaultBuilder, DefaultLocator};
use futures::future::FutureExt;
use futures::future::Shared;
use futures_util::future::{FutureExt, Shared};
use std::cell::{RefCell, RefMut}; use std::cell::{RefCell, RefMut};
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; use std::error::Error;

3
src/symbols/git/checkout.rs

@ -147,8 +147,7 @@ mod test {
] ]
); );
drop(first_two_args); drop(first_two_args);
assert_eq!(args[2],
["-C", "target", "rev-list", "-1", "FETCH_HEAD"]);
assert_eq!(args[2], ["-C", "target", "rev-list", "-1", "FETCH_HEAD"]);
assert!((end - start).as_millis() >= 100); assert!((end - start).as_millis() >= 100);
assert!((end - start).as_millis() < 150); assert!((end - start).as_millis() < 150);

Loading…
Cancel
Save