ThreadJS Example 1

Simple job with with array iteration

by ashanfer

HTML

<script src="https://raw.githubusercontent.com/AshanFernando/ThreadJS/master/thread.min.js"></script>

JavaScript

var thread = new Thread();
thread.start(1000000000, function (size) {
    var x = 0;
    for (var i = 1; i < size; i++) {
        x = x + i;
    }
    return x;
}).then(function (result) {
    console.log(result);
    this.close();
}).fail(function (error) {
    console.log(error);
});