Update grafana-data-source to tokio 0.2 (#4441)

This commit is contained in:
Ashley
2019-12-19 14:02:07 +01:00
committed by Gavin Wood
parent 8e393aa5a8
commit 9a1bb75809
5 changed files with 65 additions and 86 deletions
@@ -8,11 +8,9 @@ edition = "2018"
[dependencies]
log = "0.4.8"
hyper = { version = "0.13.0-alpha.4", default-features = false, features = ["unstable-stream"] }
tokio-io = "0.2.0-alpha.6"
tokio-executor = "0.2.0-alpha.6"
hyper = { version = "0.13.1", default-features = false, features = ["stream"] }
tokio = "0.2"
futures-util = { version = "0.3.1", default-features = false, features = ["io"] }
futures-util-alpha = { package = "futures-util-preview", default-features = false, version = "0.3.0-alpha.19" }
serde_json = "1"
serde = { version = "1", features = ["derive"] }
chrono = { version = "0.4", features = ["serde"] }
@@ -121,7 +121,7 @@ impl Datapoint {
})
}
fn make_absolute(&self, base_timestamp: i64) -> (f32, i64) {
fn make_absolute(self, base_timestamp: i64) -> (f32, i64) {
(self.value, base_timestamp + self.delta_timestamp as i64)
}
}
@@ -33,7 +33,7 @@ impl hyper::server::accept::Accept for Incoming<'_> {
pub struct TcpStream(pub async_std::net::TcpStream);
impl tokio_io::AsyncRead for TcpStream {
impl tokio::io::AsyncRead for TcpStream {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
@@ -44,7 +44,7 @@ impl tokio_io::AsyncRead for TcpStream {
}
}
impl tokio_io::AsyncWrite for TcpStream {
impl tokio::io::AsyncWrite for TcpStream {
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
@@ -17,7 +17,7 @@
use serde::{Serialize, de::DeserializeOwned};
use hyper::{Body, Request, Response, header, service::{service_fn, make_service_fn}, Server};
use chrono::{Duration, Utc};
use futures_util::{FutureExt, future::{Future, select, Either}};
use futures_util::{FutureExt, TryStreamExt, future::{Future, select, Either}};
use futures_timer::Delay;
use crate::{DATABASE, Error, types::{Target, Query, TimeseriesData, Range}};
@@ -63,9 +63,8 @@ async fn map_request_to_response<Req, Res, T>(req: Request<Body>, transformation
Res: Serialize,
T: Fn(Req) -> Res + Send + Sync + 'static
{
use futures_util_alpha::TryStreamExt;
let body = req.into_body()
.map_ok(|bytes| bytes.to_vec())
.try_concat()
.await
.map_err(Error::Hyper)?;
@@ -85,14 +84,13 @@ async fn map_request_to_response<Req, Res, T>(req: Request<Body>, transformation
pub struct Executor;
#[cfg(not(target_os = "unknown"))]
impl<T> tokio_executor::TypedExecutor<T> for Executor
impl<T> hyper::rt::Executor<T> for Executor
where
T: Future + Send + 'static,
T::Output: Send + 'static,
{
fn spawn(&mut self, future: T) -> Result<(), tokio_executor::SpawnError> {
fn execute(&self, future: T) {
async_std::task::spawn(future);
Ok(())
}
}
@@ -118,7 +116,7 @@ pub async fn run_server(mut address: std::net::SocketAddr) -> Result<(), Error>
address.set_port(0);
continue;
},
_ => Err(err)?,
_ => return Err(err.into()),
}
}
};