Created
February 4, 2021 11:04
-
-
Save Jaezmien/5aaab5302a801ea83b1ca707daee1caa to your computer and use it in GitHub Desktop.
Pause async thread and continue using a separate thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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