use crate::js::JsFutureId;
use compact_str::CompactString;
use std::time::Duration;
use tokio::sync::mpsc::Sender;
use tokio::task::JoinHandle;
#[derive(Debug)]
pub enum JsMessage {
TimeoutResp(TimeoutResp),
ExCommandReq(ExCommandReq),
}
#[derive(Debug)]
pub struct TimeoutResp {
pub future_id: JsFutureId,
pub duration: Duration,
}
impl TimeoutResp {
pub fn new(future_id: JsFutureId, duration: Duration) -> Self {
TimeoutResp {
future_id,
duration,
}
}
}
#[derive(Debug)]
pub struct ExCommandReq {
pub future_id: JsFutureId,
pub payload: CompactString,
}
impl ExCommandReq {
pub fn new(future_id: JsFutureId, payload: CompactString) -> Self {
ExCommandReq { future_id, payload }
}
}
pub fn sync_send_to_js(
master_tx: Sender<JsMessage>,
message: JsMessage,
) -> JoinHandle<()> {
tokio::runtime::Handle::current().spawn_blocking(move || {
master_tx.blocking_send(message).unwrap();
})
}