Add timeout support to car-rs streaming
This commit is contained in:
@@ -2,13 +2,13 @@ pub mod motor_control_service {
|
||||
tonic::include_proto!("motor_control");
|
||||
}
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use car_rs::{Servo, Vehicle};
|
||||
use motor_control_service::car_control_server::CarControl;
|
||||
use tonic::{Request, Response, Status, Streaming};
|
||||
|
||||
use futures_util::StreamExt;
|
||||
use motor_control_service::car_control_server::CarControl;
|
||||
use tokio::time;
|
||||
use tonic::{Request, Response, Status, Streaming};
|
||||
|
||||
use self::motor_control_service::{
|
||||
RecordingReqeust, RecordingResponse, SaveRequest, SaveResponse, SteeringRequest,
|
||||
@@ -39,14 +39,14 @@ impl CarControl for MotorControlService {
|
||||
request: Request<Streaming<Vehicle2DRequest>>,
|
||||
) -> Result<Response<Vehicle2DResponse>, Status> {
|
||||
let mut stream = request.into_inner();
|
||||
|
||||
let mut timed_out = false;
|
||||
while let Some(req) = stream.next().await {
|
||||
if !timed_out {}
|
||||
timed_out = true;
|
||||
while let Ok(Some(req)) = time::timeout(Duration::from_secs(3), stream.next()).await {
|
||||
// TODO: Set vehicle steering/throttle
|
||||
}
|
||||
|
||||
unimplemented!()
|
||||
// TODO: Stop the vehicle...
|
||||
// self.vehicle.stop();
|
||||
|
||||
Ok(Response::new(Vehicle2DResponse {}))
|
||||
}
|
||||
|
||||
async fn record(
|
||||
|
||||
Reference in New Issue
Block a user