-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2aa4f5
commit b2bb1ec
Showing
7 changed files
with
59 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export class Simulator { | ||
public isPlaying = false; | ||
public isPlayingPromise: Promise<void>; | ||
private isPlayingResolver!: () => void; | ||
private onPlay: (() => void) | undefined; | ||
private onStop: (() => void) | undefined; | ||
|
||
constructor(onPlay?: () => void, onStop?: () => void) { | ||
this.onPlay = onPlay; | ||
this.onStop = onStop; | ||
this.isPlayingPromise = new Promise((r) => { | ||
this.isPlayingResolver = r; | ||
}); | ||
} | ||
|
||
start() { | ||
if (this.isPlaying) { | ||
return; | ||
} | ||
|
||
this.isPlaying = true; | ||
this.isPlayingResolver(); | ||
this.onPlay?.(); | ||
} | ||
|
||
pause() { | ||
if (!this.isPlaying) { | ||
return; | ||
} | ||
|
||
this.isPlaying = false; | ||
this.isPlayingPromise = new Promise((r) => { | ||
this.isPlayingResolver = r; | ||
}); | ||
this.onStop?.(); | ||
} | ||
|
||
getStatus() { | ||
return this.isPlayingPromise; | ||
} | ||
} |