@@ -21,17 +21,16 @@ var worker = (function () {
21
21
22
22
var workerString = worker . toString ( ) ;
23
23
var code = workerString . substring ( workerString . indexOf ( "{" ) + 1 , workerString . lastIndexOf ( "return" ) ) ;
24
-
25
24
function execute ( param ) {
26
25
return new Promise ( function ( resolve , reject ) {
27
26
var webWorker = new Worker ( URL . createObjectURL ( new Blob ( [ code ] , { type : 'text/javascript' } ) ) ) ;
28
- var copy = Object . assign ( { } , param , { fn : param . fn . toString ( ) } ) ;
29
- webWorker . postMessage ( [ copy ] ) ;
30
27
webWorker . onmessage = function ( result ) {
31
28
if ( param . context ) Object . assign ( param . context , result . data [ 1 ] ) ;
32
29
resolve ( result . data [ 0 ] ) ;
33
30
} ;
34
31
webWorker . onerror = reject ;
32
+ var copy = Object . assign ( { } , param , { fn : param . fn . toString ( ) } ) ;
33
+ webWorker . postMessage ( [ copy ] ) ;
35
34
} ) ;
36
35
}
37
36
@@ -42,7 +41,10 @@ var params = {
42
41
fn : func . toString ( ) ,
43
42
args : [ 2 ]
44
43
} ;
45
- execute ( params ) . then ( console . log ) . catch ( console . error ) ;
44
+
45
+ var ex1 = ( function ( ) {
46
+ return execute ( params ) ;
47
+ } ) ;
46
48
47
49
function Func ( value ) {
48
50
this . value = value ;
@@ -55,7 +57,10 @@ var params$1 = {
55
57
fn : instance . foo ,
56
58
context : instance
57
59
} ;
58
- execute ( params$1 ) . then ( console . log ) . catch ( console . error ) ;
60
+
61
+ var ex2 = ( function ( ) {
62
+ return execute ( params$1 ) ;
63
+ } ) ;
59
64
60
65
function Func$1 ( value ) {
61
66
this . value = value ;
@@ -69,7 +74,10 @@ var params$2 = {
69
74
context : instance$1 ,
70
75
args : [ 4 ]
71
76
} ;
72
- execute ( params$2 ) . then ( console . log ) . catch ( console . error ) ;
77
+
78
+ var ex3 = ( function ( ) {
79
+ return execute ( params$2 ) ;
80
+ } ) ;
73
81
74
82
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
75
83
@@ -99,4 +107,31 @@ var params$3 = {
99
107
args : [ 4 ]
100
108
} ;
101
109
102
- execute ( params$3 ) . then ( console . log ) . catch ( console . error ) ;
110
+ var ex4 = ( function ( ) {
111
+ return execute ( params$3 ) ;
112
+ } ) ;
113
+
114
+ var element1 = document . getElementById ( "el1" ) ;
115
+ var element2 = document . getElementById ( "el2" ) ;
116
+ var element3 = document . getElementById ( "el3" ) ;
117
+ var element4 = document . getElementById ( "el4" ) ;
118
+ ex1 ( ) . then ( function ( result ) {
119
+ element1 . innerHTML = result ;
120
+ } ) . catch ( function ( ) {
121
+ element1 . innerHTML = "Fail" ;
122
+ } ) ;
123
+ ex2 ( ) . then ( function ( result ) {
124
+ element2 . innerHTML = result ;
125
+ } ) . catch ( function ( ) {
126
+ element2 . innerHTML = "Fail" ;
127
+ } ) ;
128
+ ex3 ( ) . then ( function ( result ) {
129
+ element3 . innerHTML = result ;
130
+ } ) . catch ( function ( ) {
131
+ element3 . innerHTML = "Fail" ;
132
+ } ) ;
133
+ ex4 ( ) . then ( function ( result ) {
134
+ element4 . innerHTML = result ;
135
+ } ) . catch ( function ( ) {
136
+ element4 . innerHTML = "Fail" ;
137
+ } ) ;
0 commit comments