@@ -33,28 +33,28 @@ export default class BrowserSolver {
33
33
}
34
34
35
35
if ( window . Worker ) {
36
- if ( this . _worker ) {
37
- clearTimeout ( this . _timeoutId ) ;
38
- this . _worker . terminate ( ) ;
36
+ if ( ! this . _worker ) {
37
+ this . _worker = new Worker ( "assets/workers/RegExWorker.js" ) ;
39
38
}
40
-
41
- let worker = this . _worker = new Worker ( "assets/workers/RegExWorker.js" ) ;
42
-
43
- worker . onmessage = ( evt ) => {
39
+
40
+ this . _worker . onmessage = ( evt ) => {
44
41
if ( evt . data === "onload" ) {
45
42
this . _startTime = Utils . now ( ) ;
46
- this . _timeoutId = setTimeout ( ( ) => {
43
+ this . _timeoutId = setTimeout ( ( ) => {
44
+ this . _worker . terminate ( ) ;
45
+ this . _worker = null ;
47
46
this . _onRegExComplete ( { id : "timeout" } ) ; // TODO: make this a warning, and return all results so far.
48
- worker . terminate ( ) ;
49
47
} , 250 ) ;
50
48
} else {
51
49
clearTimeout ( this . _timeoutId ) ;
52
50
this . _onRegExComplete ( evt . data . error , evt . data . matches , evt . data . mode ) ;
53
51
}
54
52
} ;
55
-
53
+
54
+ clearTimeout ( this . _timeoutId ) ;
55
+
56
56
// we need to pass the pattern and flags as text, because Safari strips the unicode flag when passing a RegExp to a Worker
57
- worker . postMessage ( { pattern :o . pattern , flags :o . flags , text, tests, mode} ) ;
57
+ this . _worker . postMessage ( { pattern :o . pattern , flags :o . flags , text, tests, mode} ) ;
58
58
} else {
59
59
this . _startTime = Utils . now ( ) ;
60
60
0 commit comments