mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 15:43:48 +00:00
[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:
15
example/worker/src/FibonacciWorker.js
Normal file
15
example/worker/src/FibonacciWorker.js
Normal 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));
|
||||
};
|
||||
}());
|
Reference in New Issue
Block a user