use futures::channel::oneshot;
use polkadot_node_subsystem::errors::RuntimeApiError;
use polkadot_primitives::SessionIndex;
#[allow(missing_docs)]
#[fatality::fatality(splitable)]
pub enum Error {
#[fatal]
#[error("Runtime request got canceled")]
RuntimeRequestCanceled(#[from] oneshot::Canceled),
#[error("Runtime API error {0}")]
RuntimeRequest(#[from] RuntimeApiError),
#[error("There was no session with the given index {0}")]
NoSuchSession(SessionIndex),
}
pub type Result<T> = std::result::Result<T, Error>;
pub async fn recv_runtime<V>(
r: oneshot::Receiver<std::result::Result<V, RuntimeApiError>>,
) -> Result<V> {
let result = r
.await
.map_err(FatalError::RuntimeRequestCanceled)?
.map_err(JfyiError::RuntimeRequest)?;
Ok(result)
}