host: expose harness state and actions over the world API
This commit is contained in:
@@ -15,6 +15,14 @@ pub enum Input {
|
||||
#[serde(rename = "requestId")]
|
||||
request_id: String,
|
||||
},
|
||||
Api {
|
||||
id: String,
|
||||
method: String,
|
||||
path: String,
|
||||
body: Value,
|
||||
#[serde(skip)]
|
||||
reply: mpsc::UnboundedSender<Value>,
|
||||
},
|
||||
Stop,
|
||||
}
|
||||
|
||||
@@ -31,8 +39,20 @@ pub(super) struct Inbox(pub tokio::sync::Mutex<Receiver>);
|
||||
#[serde]
|
||||
pub async fn op_input(state: Rc<RefCell<OpState>>) -> Result<serde_json::Value, JsErrorBox> {
|
||||
let inbox = state.borrow().borrow::<Rc<Inbox>>().clone();
|
||||
serde_json::to_value(inbox.0.lock().await.recv().await)
|
||||
.map_err(|error| JsErrorBox::generic(error.to_string()))
|
||||
let input = inbox.0.lock().await.recv().await;
|
||||
if let Some(Input::Api { id, reply, .. }) = &input {
|
||||
state
|
||||
.borrow_mut()
|
||||
.borrow_mut::<super::http::Replies>()
|
||||
.insert(
|
||||
id.clone(),
|
||||
super::http::Reply {
|
||||
sender: reply.clone(),
|
||||
finished: Default::default(),
|
||||
},
|
||||
);
|
||||
}
|
||||
serde_json::to_value(input).map_err(|error| JsErrorBox::generic(error.to_string()))
|
||||
}
|
||||
|
||||
pub(super) fn console(sender: Sender) {
|
||||
|
||||
Reference in New Issue
Block a user