1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 16:51:15 +02:00

Update to async/await-enabled tokio

This commit is contained in:
Eelco Dolstra 2019-12-04 15:32:28 +01:00
parent 7f08975050
commit a6f0bef0a7
7 changed files with 274 additions and 533 deletions

View file

@ -14,10 +14,9 @@ pub extern "C" fn unpack_tarfile(
#[no_mangle]
pub extern "C" fn rust_test() {
/*
use crate::store::{self, Store};
use futures::future::{FutureExt, TryFutureExt};
use std::path::Path;
use tokio::runtime::Runtime;
let fut = async move {
let store: Box<dyn Store> = Box::new(store::BinaryCacheStore::new(
@ -36,17 +35,21 @@ pub extern "C" fn rust_test() {
eprintln!("INFO = {:?}", info);
*/
let closure = store.compute_path_closure(vec![path].into_iter().collect()).await.unwrap();
let closure = store
.compute_path_closure(vec![path].into_iter().collect())
.await
.unwrap();
eprintln!("CLOSURE = {:?}", closure.len());
Ok(())
};
tokio::run(fut.boxed().compat());
*/
let rt = Runtime::new().unwrap();
rt.block_on(fut);
/*
let file = std::fs::File::open("test.nar").unwrap();
crate::nar::parse(&mut std::io::BufReader::new(file)).unwrap();
*/
}

View file

@ -1,5 +1,3 @@
#![feature(await_macro, async_await)]
#[macro_use]
extern crate lazy_static;

View file

@ -1,6 +1,5 @@
use super::{Store, StorePath, PathInfo};
use super::{PathInfo, Store, StorePath};
use crate::Error;
use futures::compat::Future01CompatExt;
pub struct BinaryCacheStore {
base_uri: String,
@ -27,22 +26,17 @@ impl Store for BinaryCacheStore {
let store_dir = self.store_dir().to_string();
Box::pin(async move {
let response = client
.get(&uri)
.send()
.compat()
.await?;
let response = client.get(&uri).send().await?;
if response.status() == reqwest::StatusCode::NOT_FOUND || response.status() == reqwest::StatusCode::FORBIDDEN {
if response.status() == reqwest::StatusCode::NOT_FOUND
|| response.status() == reqwest::StatusCode::FORBIDDEN
{
return Err(Error::InvalidPath(path));
}
let mut response = response.error_for_status()?;
let response = response.error_for_status()?;
let body = response
.text()
.compat()
.await?;
let body = response.text().await?;
PathInfo::parse_nar_info(&body, &store_dir)
})