[Workers] Add example worker

Add an example worker which inefficiently calculates
fibonacci numbers outside of the UI thread, for #12.
This commit is contained in:
Victor Woeltjen
2015-06-18 11:21:00 -07:00
parent 7d911a3fe0
commit 640a399278
5 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,15 @@
/*global onmessage,postMessage*/
(function () {
"use strict";
// Calculate fibonacci numbers inefficiently.
// We can do this because we're on a background thread, and
// won't halt the UI.
function fib(n) {
return n < 2 ? n : (fib(n - 1) + fib(n - 2));
}
onmessage = function (event) {
postMessage(fib(event.data));
};
}());