Logo white

ADAM / AIAHTML5

Sign in
  • Sign in
  • Project
  • Files
  • Commits
  • Network
  • Graphs
  • Milestones
  • Issues
  • Merge Requests 14
  • Labels
  • Wiki
  • Snippets
  • AIAHTML5
  • 400-SOURCECODE
  • AIAHTML5.Web
  • libs
  • worker.js
  • Working Worker process sample code inside AIA
    9e21c12e
    Nikita Kulshreshtha authored
    2016-07-01 18:16:13 +0530  
    Browse Code »
worker.js 455 Bytes
Edit Raw Blame History Permalink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
onmessage = function (event) {
    var arguments = JSON.parse(event.data);
    run(arguments.start, arguments.end);
};
function run(start, end) {
    var n = start;

    while (n < end) {
        var k = Math.sqrt(n);
        var found = false;

        for (var i = 2; !found && i <= k; ++i) {
            found = n % i === 0;
        }

        if (!found) {
            postMessage(n.toString());
        }

        n++;
    }
}