Browse Source

Use futures_util

master
Adrian Heine 6 months 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]
users = "0.11.0"
regex = "1.0.1"
futures = "0.3"
futures-util = "0.3"
async-trait = "0.1"
tokio = { version = "1.6.1", features = ["rt", "process", "io-util", "macros", "sync"] }
once_cell = "1.4"

6
src/async_utils.rs

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

6
src/command_runner.rs

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

3
src/setup/setup.rs

@ -6,8 +6,7 @@ use crate::async_utils::sleep;
use crate::loggers::{Logger, StoringLogger};
use crate::resources::{DefaultArtifacts, DefaultResources, FromArtifact, FromResource};
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::collections::HashMap;
use std::error::Error;

3
src/symbols/git/checkout.rs

@ -147,8 +147,7 @@ mod test {
]
);
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() < 150);

Loading…
Cancel
Save