Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /** |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | onmessage = function(event) { |
michael@0 | 6 | var n = parseInt(event.data); |
michael@0 | 7 | |
michael@0 | 8 | if (n < 2) { |
michael@0 | 9 | postMessage(n); |
michael@0 | 10 | return; |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | var results = []; |
michael@0 | 14 | for (var i = 1; i <= 2; i++) { |
michael@0 | 15 | var worker = new Worker("fibonacci_worker.js"); |
michael@0 | 16 | worker.onmessage = function(event) { |
michael@0 | 17 | results.push(parseInt(event.data)); |
michael@0 | 18 | if (results.length == 2) { |
michael@0 | 19 | postMessage(results[0] + results[1]); |
michael@0 | 20 | } |
michael@0 | 21 | }; |
michael@0 | 22 | worker.postMessage(n - i); |
michael@0 | 23 | } |
michael@0 | 24 | } |