{"size": 736, "ext": "js", "max_stars_repo_path": "controller/schedule.js", "max_stars_repo_name": "eynol/OutdoorGamesNotificationBackend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "controller/schedule.js", "max_issues_repo_name": "eynol/OutdoorGamesNotificationBackend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "controller/schedule.js", "max_forks_repo_name": "eynol/OutdoorGamesNotificationBackend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.4, "max_line_length": 54, "alphanum_fraction": 0.6073369565}
var schedule = require('node-schedule');

const game = {
  begin: new Map(),
  end: new Map()
};


exports.whenGameBeginAt = function (gid, date, func) {
  const job = schedule.scheduleJob(date, () => {
    func();
    game.begin.delete(gid);
  });
  game.begin.set(gid, job);

};

exports.cancelAutoBegin = function (gid) {
  const job = game.begin.get(gid);
  if (job) {
    job.cancel();
  }
  game.begin.delete(gid);
};

exports.whenGameEndAt = function (gid, date, func) {
  const job = schedule.scheduleJob(date, () => {
    func();
    game.end.delete(gid);
  });
  game.end.set(gid, job);
};

exports.cancelAutoEnd = function (gid) {
  const job = game.end.get(gid);
  if (job) {
    job.cancel();
  }
  game.end.delete(gid);
};