{"size": 486, "ext": "js", "max_stars_repo_path": "src/ImageManager.js", "max_stars_repo_name": "nebularazer/SeedlingDropV2-RevengeOfTheNewts", "max_stars_repo_stars_event_min_datetime": "2020-08-01T22:19:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T14:38:53.000Z", "max_issues_repo_path": "src/ImageManager.js", "max_issues_repo_name": "nebularazer/SeedlingDropV2-RevengeOfTheNewts", "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:07:40.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-30T18:13:28.000Z", "max_forks_repo_path": "src/ImageManager.js", "max_forks_repo_name": "nebularazer/SeedlingDropV2-RevengeOfTheNewts", "max_forks_repo_forks_event_min_datetime": "2020-08-01T23:00:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T14:38:58.000Z"}
{"max_stars_count": 7, "max_issues_count": 4, "max_forks_count": 11, "avg_line_length": 20.25, "max_line_length": 51, "alphanum_fraction": 0.5534979424}
export default class ImageManager {
  /**
   * @param {import('p5')} p5
   */
  constructor(p5) {
    this.p5 = p5;
    this.cache = new Map();
  }

  async getImage(url) {
    if (this.cache.has(url)) {
      return this.cache.get(url);
    }

    const imagePromise = new Promise((resolve) => {
      this.p5.loadImage(url, (image) => {
        this.cache.set(url, image);
        resolve(image);
      });
    });
    this.cache.set(url, imagePromise);
    return imagePromise;
  }
}