diff --git a/src/api2/admin/datastore/h2upload.rs b/src/api2/admin/datastore/h2upload.rs index 4e03b665..5524bd1b 100644 --- a/src/api2/admin/datastore/h2upload.rs +++ b/src/api2/admin/datastore/h2upload.rs @@ -163,12 +163,21 @@ fn backup_api() -> Router { .get( ApiMethod::new( test1_get, - ObjectSchema::new("Test something.") + ObjectSchema::new("Test sync callback.") + ) + ); + + let test2 = Router::new() + .download( + ApiAsyncMethod::new( + test2_get, + ObjectSchema::new("Test async callback.") ) ); let router = Router::new() .subdir("test1", test1) + .subdir("test2", test2) .list_subdirs(); router @@ -183,3 +192,30 @@ fn test1_get ( Ok(Value::Null) } + +fn test2_get( + parts: Parts, + req_body: Body, + param: Value, + _info: &ApiAsyncMethod, + rpcenv: &mut RpcEnvironment, +) -> Result { + let delay_unauth_time = std::time::Instant::now() + std::time::Duration::from_millis(3000); + + let fut = tokio::timer::Interval::new_interval(std::time::Duration::from_millis(300)) + .map_err(|err| http_err!(INTERNAL_SERVER_ERROR, format!("tokio timer interval error: {}", err))) + .take(10) + .for_each(|tv| { + println!("LOOP {:?}", tv); + Ok(()) + }) + .and_then(|_| { + println!("TASK DONE"); + Ok(Response::builder() + .status(StatusCode::OK) + .body(Body::empty()) + .unwrap()) + }); + + Ok(Box::new(fut)) +}