Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created December 4, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Willmo36/d0a4bbfbd82971db71dc2397edc8fcc0 to your computer and use it in GitHub Desktop.
Save Willmo36/d0a4bbfbd82971db71dc2397edc8fcc0 to your computer and use it in GitHub Desktop.
class Batching {
updateRequested = false;
async scheduleUpdate(id: number) {
if (!this.updateRequested) {
this.updateRequested = true;
this.updateRequested = await false;
this.update(id);
}
}
update(id: number) {
console.log("updating!", id);
}
}
const batching = new Batching();
/* We call scheduleUpdate in quick succession */
/** will only log once though */
batching.scheduleUpdate(1);
batching.scheduleUpdate(2);
batching.scheduleUpdate(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment