Events

Resource manager is able to notify its subscribers about specific events of resources. There are four kinds of resource events:

  1. Loaded - occurs when a resource was fully loaded without any errors.
  2. Reloaded - occurs when a resource was already fully loaded, but was reloaded by an explicit request.
  3. Added - occurs when a resource was just added to the resource manager. This event is fired right after a resource was requested from the manager.
  4. Removed - occurs when a resource was removed from the resource manager. This event is fired when the resource manager removes and unloads an unused resource.

To subscribe for resource events use the event broadcaster:

#![allow(unused)]
fn main() {
pub fn subscribe_to_events(resource_manager: &ResourceManager) {
    let (sender, receiver) = channel();
    resource_manager.state().event_broadcaster.add(sender);

    while let Ok(event) = receiver.try_recv() {
        match event {
            ResourceEvent::Loaded(_) => {}
            ResourceEvent::Reloaded(_) => {}
            ResourceEvent::Added(_) => {}
            ResourceEvent::Removed(_) => {}
        }
    }
}

}