pub struct BlackHole<J>where
J: Job,{ /* private fields */ }
Expand description
Black Hole
Usage
You should call escape_on_idle()
when done with this.
Be careful when you manually call drop()
on a black hole, or simply let it go out of scope. Because background threads are
left unmanaged.
They will keep running until main thread exits. Then they will be cancelled/discarded by the system.
Notes
Messages printed by background threads are prefixed with TAG
.
Implementations§
source§impl<J> BlackHole<J>where
J: Job,
impl<J> BlackHole<J>where
J: Job,
sourcepub fn make(queue_limit: usize) -> Result<Self>
pub fn make(queue_limit: usize) -> Result<Self>
Makes new instance with default active limit
Notes
- Default active limit is the value of
available_parallelism()
. - See
make_with_active_limit()
for more details.
sourcepub fn make_with_active_limit(
active_limit: ActiveLimit,
queue_limit: usize
) -> Result<Self>
pub fn make_with_active_limit(
active_limit: ActiveLimit,
queue_limit: usize
) -> Result<Self>
Makes new instance
Notes
- Active limit and queue limit are declared in different types to help prevent typos.
- An error is returned if either active limit or queue limit is zero.
- Internal vectors used for jobs will be made immediately with capacities of active limit and queue limit.
sourcepub fn throw(&self, job: J) -> Result<Option<J>>
pub fn throw(&self, job: J) -> Result<Option<J>>
Throws new job into the black hole
- If the job is accepted,
None
is returned. - If the job is not accepted, it is returned to you for recovery.
sourcepub unsafe fn escape(self) -> Result<()>
pub unsafe fn escape(self) -> Result<()>
Escapes the black hole
Notes
- New jobs and all waiting jobs are discarded.
- Active jobs are left untouched. They will be discarded by system when the program’s main thread exits.