Skip to content

Instantly share code, notes, and snippets.

@Jaezmien
Created February 4, 2021 11:04
Show Gist options
  • Save Jaezmien/5aaab5302a801ea83b1ca707daee1caa to your computer and use it in GitHub Desktop.
Save Jaezmien/5aaab5302a801ea83b1ca707daee1caa to your computer and use it in GitHub Desktop.
Pause async thread and continue using a separate thread
export default class Pauser {
private paused: boolean = false;
private resolve: any = undefined;
Pause() {
if( this.paused ) return;
this.paused = true;
return new Promise((res) => { this.resolve = res; });
}
Continue() { if( this.paused ) { this.resolve(); this.paused = false; } }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment