onmessage = function (event) {
  // doesn't matter what the message is, just start the job
  run();
};

function run() {
  var n = 1;
  search: while (true) {
    n += 1;
    for (var i = 2; i <= Math.sqrt(n); i += 1)
      if (n % i == 0)
       continue search;
    // found a prime!
    postMessage(n);
  }
}
