@@ -16,16 +16,32 @@ Object.defineProperty(publicApi, "getRunningSimulator", {
16
16
return new Promise < any > ( ( resolve , reject ) => {
17
17
let libraryPath = require ( "./iphone-simulator-xcode-simctl" ) ;
18
18
let simulator = new libraryPath . XCodeSimctlSimulator ( ) ;
19
- let repeatCount = 30 ;
20
- let timer = setInterval ( ( ) => {
21
- let result = simulator . getBootedDevice . apply ( simulator , args ) ;
22
- if ( ( result || ! repeatCount ) && ! isResolved ) {
23
- isResolved = true ;
24
- clearInterval ( timer ) ;
25
- resolve ( result ) ;
19
+
20
+ const tryGetBootedDevice = ( ) => {
21
+ try {
22
+ return simulator . getBootedDevice . apply ( simulator , args ) ;
23
+ } catch ( err ) {
24
+ if ( ! isResolved ) {
25
+ isResolved = true ;
26
+ reject ( err ) ;
27
+ }
26
28
}
27
- repeatCount -- ;
28
- } , 500 ) ;
29
+ }
30
+
31
+ let result = tryGetBootedDevice ( ) ;
32
+
33
+ if ( ! isResolved && ! result ) {
34
+ let repeatCount = 30 ;
35
+ let timer = setInterval ( ( ) => {
36
+ result = tryGetBootedDevice ( ) ;
37
+ if ( ( result || ! repeatCount ) && ! isResolved ) {
38
+ isResolved = true ;
39
+ clearInterval ( timer ) ;
40
+ resolve ( result ) ;
41
+ }
42
+ repeatCount -- ;
43
+ } , 500 ) ;
44
+ }
29
45
} ) ;
30
46
}
31
47
}
@@ -39,16 +55,32 @@ Object.defineProperty(publicApi, "getRunningSimulators", {
39
55
return new Promise < any > ( ( resolve , reject ) => {
40
56
const libraryPath = require ( "./iphone-simulator-xcode-simctl" ) ;
41
57
const simulator = new libraryPath . XCodeSimctlSimulator ( ) ;
42
- let repeatCount = 30 ;
43
- const timer = setInterval ( ( ) => {
44
- const result = simulator . getBootedDevices . apply ( simulator , args ) ;
45
- if ( ( result || ! repeatCount ) && ! isResolved ) {
46
- isResolved = true ;
47
- clearInterval ( timer ) ;
48
- resolve ( result ) ;
58
+
59
+ const tryGetBootedDevices = ( ) => {
60
+ try {
61
+ return simulator . getBootedDevices . apply ( simulator , args ) ;
62
+ } catch ( err ) {
63
+ if ( ! isResolved ) {
64
+ isResolved = true ;
65
+ reject ( err ) ;
66
+ }
49
67
}
50
- repeatCount -- ;
51
- } , 500 ) ;
68
+ }
69
+
70
+ let result = tryGetBootedDevices ( ) ;
71
+
72
+ if ( ! isResolved && ! result ) {
73
+ let repeatCount = 30 ;
74
+ const timer = setInterval ( ( ) => {
75
+ result = tryGetBootedDevices ( ) ;
76
+ if ( ( result || ! repeatCount ) && ! isResolved ) {
77
+ isResolved = true ;
78
+ clearInterval ( timer ) ;
79
+ resolve ( result ) ;
80
+ }
81
+ repeatCount -- ;
82
+ } , 500 ) ;
83
+ }
52
84
} ) ;
53
85
}
54
86
}
0 commit comments