Changeset 1005

Show
Ignore:
Timestamp:
07/31/08 02:39:18 (1 month ago)
Author:
MaierMan
Message:

Small refinements in CoThread?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/modules/cothread.jsm

    r1004 r1005  
    4444const Timer = Components.Constructor('@mozilla.org/timer;1', 'nsITimer', 'initWithCallback'); 
    4545 
     46// "Abstract" base c'tor 
     47function CoThreadBase(func, yieldEvery, thisCtx) { 
     48        this._thisCtx = thisCtx ? thisCtx : this; 
     49         
     50        // default to 1 
     51        this._yieldEvery = typeof yieldEvery == 'number' ? Math.floor(yieldEvery) : 1; 
     52        if (yieldEvery < 1) { 
     53                throw Cr.NS_ERROR_INVALID_ARG; 
     54        } 
     55         
     56        if (typeof func != 'function' && !(func instanceof Function)) { 
     57                throw Cr.NS_ERROR_INVALID_ARG; 
     58        }  
     59        this._func = func; 
     60} 
     61 
    4662/** 
    4763 * Constructs a new CoThread (aka. pseudo-thread). 
     
    6783 */ 
    6884function CoThread(func, yieldEvery, thisCtx) { 
    69          
    70         this._thisCtx = thisCtx ? thisCtx : this; 
    71          
    72         // default to 1 
    73         this._yieldEvery = typeof yieldEvery == 'number' ? Math.floor(yieldEvery) : 1; 
    74         if (yieldEvery < 1) { 
    75                 throw Cr.NS_ERROR_INVALID_ARG; 
    76         } 
    77          
    78         if (typeof func != 'function' && !(func instanceof Function)) { 
    79                 throw Cr.NS_ERROR_INVALID_ARG; 
    80         }  
    81         this._func = func; 
    82  
     85        CoThreadBase.call(this, func, yieldEvery, thisCtx); 
    8386        this._generator = (function() { for(;;) { yield null }; })(); 
    8487} 
     
    158161 */ 
    159162function CoThreadListWalker(func, arrayOrGenerator, yieldEvery, thisCtx) { 
    160         CoThread.call(this, func, yieldEvery, thisCtx); 
     163        CoThreadBase.call(this, func, yieldEvery, thisCtx); 
    161164         
    162165        if (arrayOrGenerator instanceof Array) {