File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,32 @@ export class UnityHubInstallerEvent extends EventEmitter implements InstallerEmi
2222 super ( ) ;
2323 }
2424
25- public completed : Promise < InstallerEvent [ ] > = new Promise ( ( resolve , reject ) => {
26- this . on ( InstallerEventType . Completed , ( events ) => resolve ( events ) ) ;
27- this . on ( InstallerEventType . Error , ( error ) => reject ( error ) ) ;
28- this . on ( InstallerEventType . Cancelled , ( events ) => reject ( new Error ( "Cancelled" ) ) ) ;
29- } ) ;
25+ public get completed ( ) : Promise < InstallerEvent [ ] > {
26+ return new Promise ( ( resolve , reject ) => {
27+ const onComplete = ( events : InstallerEvent [ ] ) => {
28+ cleanup ( ) ;
29+ resolve ( events ) ;
30+ } ;
31+ const onError = ( error : any ) => {
32+ cleanup ( ) ;
33+ reject ( error ) ;
34+ } ;
35+ const onCancel = ( ) => {
36+ cleanup ( ) ;
37+ reject ( new Error ( "Cancelled" ) ) ;
38+ } ;
39+
40+ const cleanup = ( ) => {
41+ this . off ( InstallerEventType . Completed , onComplete ) ;
42+ this . off ( InstallerEventType . Error , onError ) ;
43+ this . off ( InstallerEventType . Cancelled , onCancel ) ;
44+ } ;
45+
46+ this . on ( InstallerEventType . Completed , onComplete ) ;
47+ this . on ( InstallerEventType . Error , onError ) ;
48+ this . on ( InstallerEventType . Cancelled , onCancel ) ;
49+ } ) ;
50+ }
3051
3152 /**
3253 * Parses the raw event string and emits the appropriate event.
You can’t perform that action at this time.
0 commit comments