Trait ResourceLoadTask
pub trait ResourceLoadTask: Send + Sync {
// Required method
fn finish(&self, domain: &Domain) -> Result<Resource, Error>;
// Provided methods
fn load<'a>(&'a mut self, _enqueue_dependencies: &'a dyn Fn(&[&KanziStr])) { ... }
fn get_type(&self) -> ResourceLoadTaskType { ... }
}Expand description
Use this trait to implement the load tasks that load new resources.
A load task is split into an optional load and mandatory finish functions.
The load function may be called in a background worker thread, instead of the main thread.
And so only thread independent work should be done here.
While the finish function is guaranteed to be called in the main thread.
The load task execution happens in this order:
- The loading thread or main thread execute the
loadfunction. - The main thread executes the
finishfunction.
Inside the load function, a call to enqueue_dependencies can be made
to trigger background loading of dependencies.
Required Methods§
Provided Methods§
fn load<'a>(&'a mut self, _enqueue_dependencies: &'a dyn Fn(&[&KanziStr]))
fn load<'a>(&'a mut self, _enqueue_dependencies: &'a dyn Fn(&[&KanziStr]))
You can override this function to define the part of the resource loading task that a worker thread executes. You cannot access any shared data inside the function.
§Arguments
enqueue_dependencies- Add resource dependencies for the load task. Can be called any number of times inside aloadimplementation. Informs the main thread of the dependencies, which can then trigger their async loading.
fn get_type(&self) -> ResourceLoadTaskType
fn get_type(&self) -> ResourceLoadTaskType
Get the type of a load task.