pub struct BrowserSessionPool { /* private fields */ }Expand description
A pool of browser sessions keyed by user ID.
Use this in multi-user agent platforms where each user needs an isolated
browser instance. Sessions are created lazily via [get_or_create] and
cleaned up via [release] or [cleanup_all].
§Example
ⓘ
use adk_browser::{BrowserConfig, BrowserSessionPool};
let pool = BrowserSessionPool::new(BrowserConfig::default(), 10);
// In a tool's execute(), resolve session from user context:
let session = pool.get_or_create("user_123").await?;
session.navigate("https://example.com").await?;
// On shutdown:
pool.cleanup_all().await;Implementations§
Source§impl BrowserSessionPool
impl BrowserSessionPool
Sourcepub fn new(config: BrowserConfig, max_sessions: usize) -> Self
pub fn new(config: BrowserConfig, max_sessions: usize) -> Self
Create a new session pool.
max_sessions limits the number of concurrent browser sessions.
When the limit is reached, get_or_create will return an error.
Sourcepub async fn get_or_create(&self, user_id: &str) -> Result<Arc<BrowserSession>>
pub async fn get_or_create(&self, user_id: &str) -> Result<Arc<BrowserSession>>
Get an existing session for the user, or create a new one.
The session is started automatically if newly created. If the session exists but is stale, it will be reconnected.
Sourcepub async fn release(&self, user_id: &str) -> Result<()>
pub async fn release(&self, user_id: &str) -> Result<()>
Release and stop a user’s browser session.
Sourcepub async fn cleanup_all(&self)
pub async fn cleanup_all(&self)
Stop and remove all sessions. Call during graceful shutdown.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Number of active sessions in the pool.
Sourcepub async fn active_users(&self) -> Vec<String>
pub async fn active_users(&self) -> Vec<String>
List all user IDs with active sessions.
Auto Trait Implementations§
impl !Freeze for BrowserSessionPool
impl !RefUnwindSafe for BrowserSessionPool
impl Send for BrowserSessionPool
impl Sync for BrowserSessionPool
impl Unpin for BrowserSessionPool
impl UnsafeUnpin for BrowserSessionPool
impl !UnwindSafe for BrowserSessionPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more