pub struct WasmParallelPowGenerator { /* private fields */ }Expand description
A PowGenerator that dispatches chunks to pre-created Web Workers.
The TypeScript side is responsible for spawning and initializing the workers;
this struct simply receives the ready Worker handles and exposes one slot per worker.
All scheduling — work-stealing refeed, early exit, tracker registration — lives in the
shared run_pool dispatcher in hashiverse-lib.
Implementations§
Source§impl WasmParallelPowGenerator
impl WasmParallelPowGenerator
Sourcepub fn from_workers(workers: Vec<Worker>) -> Self
pub fn from_workers(workers: Vec<Worker>) -> Self
Create a new generator from pre-initialized Worker handles.
Trait Implementations§
Source§impl PowGenerator for WasmParallelPowGenerator
impl PowGenerator for WasmParallelPowGenerator
Source§fn pool_size(&self) -> usize
fn pool_size(&self) -> usize
How many
run_chunk calls the dispatcher may have in flight concurrently.
WasmParallelPowGenerator returns its workers.len(); the native backend returns
the CPU count; the single-threaded backend returns 1.Source§fn run_chunk<'life0, 'async_trait>(
&'life0 self,
slot: usize,
chunk_iterations: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run_chunk<'life0, 'async_trait>(
&'life0 self,
slot: usize,
chunk_iterations: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run
chunk_iterations PoW attempts on one parallel slot. slot is an opaque index
in 0..pool_size() — the wasm backend uses it to address self.workers[slot]; the
native and single-threaded backends ignore it. May short-circuit inside the chunk
when pow_min is reached (pow_compute_batch already does this in
hashiverse-client-wasm/src/lib.rs).Source§fn tracker(&self) -> &Arc<Mutex<JobTracker>>
fn tracker(&self) -> &Arc<Mutex<JobTracker>>
Accessor for the impl’s
JobTracker. Used by the default generate /
generate_best_effort impls to register the in-flight job, and by active_jobs()
to snapshot it for the UI.§fn active_jobs(&self) -> Vec<PowJobStatus>
fn active_jobs(&self) -> Vec<PowJobStatus>
Snapshot of all concurrently in-flight tracked jobs.
§fn is_pow_busy(&self, within_millis: i64) -> bool
fn is_pow_busy(&self, within_millis: i64) -> bool
Whether PoW work is happening now, or finished within the last
within_millis. Drives the
UI “busy” indicator. Stamp and query both go through RealTimeProvider so they share one
wall-clock source (matching run_pool).§fn generate_best_effort<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
iteration_limit: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn generate_best_effort<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
iteration_limit: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Run up to
iteration_limit attempts via the work-stealing pool. Registers the job
in the tracker at entry. Returns the moment any chunk produces pow >= pow_min
(discarding chunks still in flight); otherwise returns the best result found
within iteration_limit.§fn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Run the pool unbounded until
pow >= pow_min is found. Registers the job in the
tracker at entry.impl Send for WasmParallelPowGenerator
impl Sync for WasmParallelPowGenerator
Auto Trait Implementations§
impl Freeze for WasmParallelPowGenerator
impl RefUnwindSafe for WasmParallelPowGenerator
impl Unpin for WasmParallelPowGenerator
impl UnsafeUnpin for WasmParallelPowGenerator
impl UnwindSafe for WasmParallelPowGenerator
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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