Drops usages of async_std::spawn_blocking

pull/70/head
Tpt 4 years ago
parent a228d266c5
commit 7aca89016d
  1. 22
      server/src/main.rs
  2. 2
      testsuite/rdf-tests
  3. 7
      wikibase/src/main.rs

@ -14,7 +14,7 @@ use async_std::future::Future;
use async_std::io::Read; use async_std::io::Read;
use async_std::net::{TcpListener, TcpStream}; use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*; use async_std::prelude::*;
use async_std::task::{block_on, spawn, spawn_blocking}; use async_std::task::{block_on, spawn};
use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode}; use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode};
use oxigraph::io::{DatasetFormat, GraphFormat}; use oxigraph::io::{DatasetFormat, GraphFormat};
use oxigraph::model::{GraphName, NamedNode, NamedOrBlankNode}; use oxigraph::model::{GraphName, NamedNode, NamedOrBlankNode};
@ -74,31 +74,21 @@ async fn handle_request(request: Request, store: Store) -> Result<Response> {
("/", Method::Post) => { ("/", Method::Post) => {
if let Some(content_type) = request.content_type() { if let Some(content_type) = request.content_type() {
match if let Some(format) = GraphFormat::from_media_type(content_type.essence()) { match if let Some(format) = GraphFormat::from_media_type(content_type.essence()) {
spawn_blocking(move || {
store.load_graph( store.load_graph(
BufReader::new(SyncAsyncReader::from(request)), BufReader::new(SyncAsyncReader::from(request)),
format, format,
&GraphName::DefaultGraph, &GraphName::DefaultGraph,
None, None,
) )
})
} else if let Some(format) = DatasetFormat::from_media_type(content_type.essence()) } else if let Some(format) = DatasetFormat::from_media_type(content_type.essence())
{ {
spawn_blocking(move || { store.load_dataset(BufReader::new(SyncAsyncReader::from(request)), format, None)
store.load_dataset(
BufReader::new(SyncAsyncReader::from(request)),
format,
None,
)
})
} else { } else {
return Ok(simple_response( return Ok(simple_response(
StatusCode::UnsupportedMediaType, StatusCode::UnsupportedMediaType,
format!("No supported content Content-Type given: {}", content_type), format!("No supported content Content-Type given: {}", content_type),
)); ));
} } {
.await
{
Ok(()) => Response::new(StatusCode::NoContent), Ok(()) => Response::new(StatusCode::NoContent),
Err(error) => { Err(error) => {
return Err(bad_request(error)); return Err(bad_request(error));
@ -226,7 +216,6 @@ async fn evaluate_sparql_query(
named_graph_uris: Vec<String>, named_graph_uris: Vec<String>,
request: Request, request: Request,
) -> Result<Response> { ) -> Result<Response> {
spawn_blocking(move || {
let mut query = Query::parse(&query, None).map_err(bad_request)?; let mut query = Query::parse(&query, None).map_err(bad_request)?;
let default_graph_uris = default_graph_uris let default_graph_uris = default_graph_uris
.into_iter() .into_iter()
@ -280,8 +269,6 @@ async fn evaluate_sparql_query(
response.insert_header(headers::CONTENT_TYPE, format.media_type()); response.insert_header(headers::CONTENT_TYPE, format.media_type());
Ok(response) Ok(response)
} }
})
.await
} }
async fn evaluate_urlencoded_sparql_update(store: Store, encoded: Vec<u8>) -> Result<Response> { async fn evaluate_urlencoded_sparql_update(store: Store, encoded: Vec<u8>) -> Result<Response> {
@ -323,7 +310,6 @@ async fn evaluate_sparql_update(
"using-graph-uri and using-named-graph-uri parameters are not supported yet", "using-graph-uri and using-named-graph-uri parameters are not supported yet",
)); ));
} }
spawn_blocking(move || {
let update = Update::parse(&update, None).map_err(|e| { let update = Update::parse(&update, None).map_err(|e| {
let mut e = Error::from(e); let mut e = Error::from(e);
e.set_status(StatusCode::BadRequest); e.set_status(StatusCode::BadRequest);
@ -331,8 +317,6 @@ async fn evaluate_sparql_update(
})?; })?;
store.update(update)?; store.update(update)?;
Ok(Response::new(StatusCode::NoContent)) Ok(Response::new(StatusCode::NoContent))
})
.await
} }
async fn http_server< async fn http_server<

@ -1 +1 @@
Subproject commit 56b69dbf6a858e09287743e601cc3ecc0577d05e Subproject commit 5979a875356911ff0175a8f8a6c2d04edecdaac1

@ -14,7 +14,7 @@ use argh::FromArgs;
use async_std::future::Future; use async_std::future::Future;
use async_std::net::{TcpListener, TcpStream}; use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*; use async_std::prelude::*;
use async_std::task::{spawn, spawn_blocking}; use async_std::task::spawn;
use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode}; use http_types::{headers, Body, Error, Method, Mime, Request, Response, Result, StatusCode};
use oxigraph::io::GraphFormat; use oxigraph::io::GraphFormat;
use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat}; use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat};
@ -79,7 +79,6 @@ pub async fn main() -> Result<()> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let slot = args.slot.clone(); let slot = args.slot.clone();
let repo = store.clone(); let repo = store.clone();
spawn_blocking(move || {
let mut loader = WikibaseLoader::new( let mut loader = WikibaseLoader::new(
repo, repo,
&mediawiki_api, &mediawiki_api,
@ -89,6 +88,7 @@ pub async fn main() -> Result<()> {
Duration::new(10, 0), Duration::new(10, 0),
) )
.unwrap(); .unwrap();
spawn(async move {
loader.initial_loading().unwrap(); loader.initial_loading().unwrap();
loader.update_loop(); loader.update_loop();
}); });
@ -173,7 +173,6 @@ async fn evaluate_sparql_query(
query: String, query: String,
request: Request, request: Request,
) -> Result<Response> { ) -> Result<Response> {
spawn_blocking(move || {
//TODO: stream //TODO: stream
let mut query = Query::parse(&query, None).map_err(|e| { let mut query = Query::parse(&query, None).map_err(|e| {
let mut e = Error::from(e); let mut e = Error::from(e);
@ -216,8 +215,6 @@ async fn evaluate_sparql_query(
response.insert_header(headers::CONTENT_TYPE, format.media_type()); response.insert_header(headers::CONTENT_TYPE, format.media_type());
Ok(response) Ok(response)
} }
})
.await
} }
async fn http_server< async fn http_server<

Loading…
Cancel
Save