Skip to content

Lightweight library for tracking loading progress

License

Notifications You must be signed in to change notification settings

Cynicollision/headway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Headway

Headway is a lightweight library for tracking loading progress. It provides a mechanism for tracking and responding to completion of asynchronous tasks.

Use Headway.track(..) to wrap asynchronous code, then call progress.update() once the asychonous part(s) have completed.

Contrived Example

  1. Track two different image-loading tasks, one a weight of 1 and a second with a weight of 3:
Headway.track(progress => {
  let img = new Image();
  img.src = '/path/to/someImage.png';
  img.onload = progress.update();
}); // default weight = 1

Headway.track(progress => {
  someAsyncCall().then(() => progress.update());
}, 3); // specific weight of 3
  1. Respond to progress updates upon each tasks' completion:
Headway.onUpdate(progress => {
  let progressPercent = progress.getPercentComplete();
  // progressPercent = 25 after task #1 completes, 100 after #2 completes.
  // (e.g. update the status of a "loading bar" visual.)
});
  1. Respond to the completion of all tasks:
Headway.onComplete(() => {
  // all tasks have completed.
  // (e.g. start the game.)
});
  1. (Optional) Reset the progress tracker for re-use.
Headway.reset();

About

Lightweight library for tracking loading progress

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published