File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed
Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,10 @@ const iterateCount = 1000;
33this . addEventListener ( "message" , event => {
44 const start = performance . now ( ) ;
55
6- const counts = [ ] ;
76 for ( let i = 0 ; i < iterateCount ; i ++ ) {
8- counts . push ( i ) ;
9- console . log ( i ) ;
7+ this . postMessage ( { num : i } ) ;
108 }
119
1210 const duration = performance . now ( ) - start ;
13- this . postMessage ( { duration : duration . toFixed ( 1 ) , counts } ) ;
11+ this . postMessage ( { duration : duration . toFixed ( 1 ) } ) ;
1412} ) ;
Original file line number Diff line number Diff line change @@ -56,6 +56,15 @@ <h1>Web Worker</h1>
5656
5757 function workerJob ( resolve , reject ) {
5858 worker . addEventListener ( "message" , event => {
59+ // write number in DOM
60+ test ( event . data . num ) ;
61+ // clean number
62+ OUTPUT . textContent = '' ;
63+
64+ if ( ! event . data . duration ) {
65+ return ;
66+ }
67+
5968 const duration = event . data . duration ;
6069
6170 runs . push ( Number ( duration ) ) ;
@@ -69,13 +78,6 @@ <h1>Web Worker</h1>
6978 resultTr . appendChild ( resultTh ) ;
7079 resultTr . appendChild ( resultTd ) ;
7180 RESULTS . appendChild ( resultTr ) ;
72-
73- const testCount = event . data . counts ;
74- testCount . forEach ( item => {
75- test ( item ) ;
76- } ) ;
77-
78- OUTPUT . textContent = '' ;
7981
8082 if ( event !== null ) {
8183 resolve ( runId ) ;
You can’t perform that action at this time.
0 commit comments