pub struct PagePool {
pub max_pages: u32,
/* private fields */
}Expand description
Thread-safe pool that tracks browser page states and enforces a capacity limit.
The pool uses a Mutex<Vec<PageInfo>> internally, making it safe to share across
async tasks. All mutation methods acquire the lock, perform the update, and release
it immediately to minimise contention.
Fields§
§max_pages: u32Maximum number of pages allowed in the pool.
Implementations§
Source§impl PagePool
impl PagePool
Sourcepub fn new(max_pages: u32) -> Self
pub fn new(max_pages: u32) -> Self
Create an empty page pool with the given capacity.
No pages are registered yet – call add_page to register
each new page as it is created by the session.
Sourcepub fn add_page(&self, page_index: usize) -> Result<()>
pub fn add_page(&self, page_index: usize) -> Result<()>
Register a new page in the pool, returning an error if the pool is full.
The page starts in the PageState::Ready state. Returns
[BrowserError::PagePool] when the number of registered pages already
equals max_pages.
Sourcepub fn mark_busy(&self, page_index: usize, url: &str)
pub fn mark_busy(&self, page_index: usize, url: &str)
Mark a page as busy and record the URL it is navigating to. Call this at the start of a fetch cycle to signal that the page is in use.
Sourcepub fn mark_ready(&self, page_index: usize)
pub fn mark_ready(&self, page_index: usize)
Mark a page as ready (idle) for reuse. Call this after a fetch cycle completes successfully.
Sourcepub fn mark_error(&self, page_index: usize)
pub fn mark_error(&self, page_index: usize)
Mark a page as having encountered an error.
The page will not be reused until it is cleaned up via
cleanup_error_pages.
Sourcepub fn pages_count(&self) -> usize
pub fn pages_count(&self) -> usize
Return the total number of pages currently in the pool (all states combined).
Sourcepub fn busy_count(&self) -> usize
pub fn busy_count(&self) -> usize
Return the number of pages currently in the Busy state.
Sourcepub fn cleanup_error_pages(&self)
pub fn cleanup_error_pages(&self)
Remove all pages in the Error state from the pool.
This frees up capacity so new pages can be registered. You should call this
periodically or after a batch of fetches to reclaim slots.