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.
Auto Trait Implementations§
impl !Freeze for PagePool
impl RefUnwindSafe for PagePool
impl Send for PagePool
impl Sync for PagePool
impl Unpin for PagePool
impl UnsafeUnpin for PagePool
impl UnwindSafe for PagePool
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more