Apq.Threading.js

Apq.namespace( "Apq.Threading" );

if( !Apq.Threading.Thread )
{
 Apq.Threading.Thread = Apq.Class( "Apq.Threading.Thread" );

 /// <t=0>启动延时时间</t>
 /// <m=true>是否允许多次排队</m>
 Apq.Threading.Thread.prototype.ctor = function( ThreadStart, t, args, o, m ){
  this.t = t || 0;
  this.ThreadStart = ThreadStart;
  this.args = args;
  this.o = o;
  this.m = m == null ? true : m;
  this.ids = []; // 排队号码集合
 };
 
 Apq.Threading.Thread.prototype.Enqueue = function(){
  if( !this.m && this.ids.length )
  {
   throw new Error( -1, "该线程不允许重复排队" );
  }
  var id = Apq.setTimeout( this.t, this.ThreadStart, arguments.length ? arguments : this.args, this.o );
  this.ids.push( id );
  return id;
 };
 
 Apq.Threading.Thread.prototype.Dequeue = function( id ){
  id = id || this.ids.concat();
  
  if( id instanceof Array )
  {
   if( id.length )
   {
    for( var i = 0; i < id.length; i++ )
    {
     this.Dequeue( id[i] );
    }
   }
   else
   {
    this.Dequeue();
   }
  }
  else if( this.ids.Contains( id ) )
  {
   clearTimeout( id );
   this.ids.Remove( id );
  }
 };
}

posted @ 2006-06-14 10:45  Amwpfiqvy  阅读(308)  评论(1编辑  收藏  举报