Thread.js

Simple, lightweight and easy.

Multi-thread JavaScript library.

Feature

No dependencies

Lightweight

Simple and Easy

Usage

a simple.

        
var thread = new Thread(function(){
  return "hello Thread.js";
});

thread.once().done(function(d){
  console.log(d);    // -> hello Thread.js
});
        
      

with arguments.

        
var thread = new Thread(function(a, b){
  return a + b;
});

thread.once(1, 2).done(function(d){
  console.log(d);    // -> 3
});
        
      

with progress.

        
var thread = new Thread(function(){
  notify("progress");
  return "hello Thread.js";
});

thread.once().progress(function(d){
  console.log(d);    // -> progress
}).done(function(d){
  console.log(d);    // -> hello Thread.js
});
        
      

with other libraries.

        
var thread = new Thread(function(){
  example();
}, [
  "http://example.com/path/to/example.js",
  "http://example.com/path/to/example2.js"
]);

thread.once().progress(function(d){
  // ...
});
        
      

Examples

Questions

Can I refer to variables outside the anonymous function?

The function passed to the constructor of Thread.js can not refer to the outer variable.

Is the argument passed to the "once()" function passed by reference?

No, any object will be "deep copy". All arguments are passed by value.

Supperted Browsers

Chrome 32 or later

FireFox 26 or later

Safari 7.1 or later

Edge 12 or later

CDN

<script src="https://cdn.rawgit.com/deep-rain/thread/1.0.0/dist/thread.min.js"></script>
      

Licence

Copyright 2017 deep-rain.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.