Skip to main content

Module progress

Module progress 

Source
Expand description

Progress event emission helpers for transfers.

§Design

emit_progress throttles emissions to at most one per 250 ms or per 256 KB transferred, whichever condition is met first. This avoids flooding the IPC channel while still giving the frontend a responsive progress bar.

emit_state is unthrottled — state transitions (Queued → Running → Done / Failed / Canceled) must always reach the frontend.

§OCP contract

The same helpers are reused for uploads (task 32) — the throttle logic lives in one place and is called identically from both download.rs and upload.rs.

Structs§

ProgressThrottle
Tracks when the last progress event was emitted so emit_progress can apply the 250 ms / 256 KB throttle.
TransferProgressPayload
Payload for transfer:progress.
TransferStatePayload
Payload for transfer:state.

Constants§

PROGRESS_THROTTLE_BYTES
Minimum bytes transferred between progress events.
PROGRESS_THROTTLE_MS
Minimum milliseconds between progress events for one transfer.

Functions§

emit_progress
Emit a transfer:progress event if the throttle gate is open.
emit_state
Emit a transfer:state event (unthrottled). Use emit_state_with_error on Failed transitions to attach the underlying AppError to the payload so the frontend can render the failure reason.
emit_state_with_error
Emit a transfer:state event with an optional AppError attached.