Skip to main content

systemprompt_models/execution/
shared_context.rs

1//! `SharedRequestContext`: mutex-shared form of `RequestContext` for async
2//! tasks.
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use super::context::RequestContext;
8use std::sync::{Arc, Mutex};
9
10pub type SharedRequestContext = Arc<Mutex<RequestContext>>;
11
12impl From<RequestContext> for SharedRequestContext {
13    fn from(context: RequestContext) -> Self {
14        Self::new(Mutex::new(context))
15    }
16}
17
18impl From<Arc<Mutex<Self>>> for RequestContext {
19    fn from(shared: Arc<Mutex<Self>>) -> Self {
20        let guard = shared
21            .lock()
22            .unwrap_or_else(std::sync::PoisonError::into_inner);
23        guard.clone()
24    }
25}