Simple scheduler in Javascript