Run the plugin until we get a shutdown command.
(
self,
mut receiver: tokio::sync::mpsc::Receiver<serde_json::Value>,
mut input: FramedRead<I, JsonRpcCodec>,
output: Arc<Mutex<FramedWrite<O, JsonCodec>>>,
)
| 492 | { |
| 493 | /// Run the plugin until we get a shutdown command. |
| 494 | async fn run<I, O>( |
| 495 | self, |
| 496 | mut receiver: tokio::sync::mpsc::Receiver<serde_json::Value>, |
| 497 | mut input: FramedRead<I, JsonRpcCodec>, |
| 498 | output: Arc<Mutex<FramedWrite<O, JsonCodec>>>, |
| 499 | ) -> Result<(), Error> |
| 500 | where |
| 501 | I: Send + AsyncReadExt + Unpin, |
| 502 | O: Send + AsyncWriteExt + Unpin, |
| 503 | { |
| 504 | loop { |
| 505 | // If we encounter any error reading or writing from/to |
| 506 | // the master we hand them up, so we can return control to |
| 507 | // the user-code, which may require some cleanups or |
| 508 | // similar. |
| 509 | tokio::select! { |
| 510 | e = self.dispatch_one(&mut input, &self.plugin) => { |
| 511 | if let Err(e) = e { |
| 512 | return Err(e) |
| 513 | } |
| 514 | }, |
| 515 | v = receiver.recv() => { |
| 516 | output.lock().await.send( |
| 517 | v.context("internal communication error")? |
| 518 | ).await?; |
| 519 | }, |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /// Dispatch one server-side event and then return. Just so we |
| 525 | /// have a nicer looking `select` statement in `run` :-) |