Class Index | File Index

Classes


Class Thread

Creates a handle to a new thread. The handle can be used to kill the thread or be ignored. The function provided is executed after an initial timeout. Note that although this looks similar to the setTimeout in web-browsers, after started, the thread will not run until completion but run in parallel to the executed script.

To stop the script from within a thread, use exit(). To stop only execution of the thread (silently) throw a null exception ("throw null;"). To terminate the script with an exception throw a normal exception ("throw new Error("my error");"). Note that a running thread might consume all CPU. Although it is a seperated thread, JavaScript allows only one thread to run at a time (thus it can make programming simpler, but is not really consuming more CPU). In certain circumstances, it might be necessary to give CPU time with v8.sleep(...) back to allow other threads to run.
Defined in: Thread.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Thread(timeout, function, _this)
Method Summary
Method Attributes Method Name and Description
 
kill()
Kills a running thread
Class Detail
Thread(timeout, function, _this)
   var handle = new Thread(100, function() { console.out("Hello world!"); });
   ...
   handle.kill();
Parameters:
{Integer} timeout
A positive integer given the initial delay in milliseconds before the thread is executed.
{Function} function
A function which is executed aftr the initial timeout.
{Object} _this Optional
An object which will be the reference for 'this' in the function call. If none is given, the function itself will be the 'this' object.
Throws:
  • If number or type of arguments is wrong
  • Method Detail
    {Boolean} kill()
    Kills a running thread
    Returns:
    {Boolean} If the thread was still known, true is returned, false otherwise. If the thread terminated already, false is returned.

    Documentation generated by JsDoc Toolkit 2.4.0 on Sun Sep 18 2016 20:50:08 GMT+0100 (WEST)