Benutzer:J*/lib/async.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt.
 
Keine Bearbeitungszusammenfassung
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 10: Zeile 10:
{
{
     var asyncobj = this;
     var asyncobj = this;
     arr.each( function(d) { asyncobj.push(d); } );
     for (var i=0; i< arr.length; i++)
        asyncobj.push(arr[i]);
     this.pointer = 0;
     this.pointer = 0;
     this.ondone = ondone;
     this.ondone = ondone;
Zeile 31: Zeile 32:


     this._control = function ( obj ) {
     this._control = function ( obj ) {
        console.log("_control", obj);
         if (this.pointer >= this.length)
         if (this.pointer >= this.length)
         {
         {
             if (typeof(this.ondone)=="function")
             if (typeof(this.ondone)=="function")
             {
             {
                alert("Return: Function")
                 this.ondone( obj, this );
                 this.ondone( obj, this );
                 return
                 return;
             }
             }
             if (typeof(this.ondone)=="object") // instanceof gibt hier nur ärger
             if (typeof(this.ondone)=="object") // instanceof gibt hier nur ärger
             {
             {
                alert("Return: object")
                 this.ondone.continue( obj );
                 this.ondone.continue( obj );
                 return
                 return;
             }
             }
         }
         }


        if (this[this.pointer]==null)
            return;
         if (typeof(this[this.pointer])=="function")
         if (typeof(this[this.pointer])=="function")
         {
         {
             this.continue( this[this.pointer]( obj, this ) );
             this.continue( this[this.pointer]( obj, this ) );
             return
             return;
         }
         }
         if (this[this.pointer] instanceof Async)
         if (typeof(this[this.pointer])=="object") //auch hier gibt's Probleme mit instanceof
         {
         {
             this[this.pointer].start( obj, this );
             this[this.pointer].start( obj, this );
             return
             return;
         }
         }
          
          

Aktuelle Version vom 22. Mai 2015, 07:07 Uhr

/* +-------------------------------------------------------------------------+
 * |                                                                         |
 * |  Modul 2: Die Async-Klasse, um asynchrone Vorgänge behandeln zu können  |
 * |           mehr Erklärung gibt's woanders ... vielleicht ...             |
 * |                                                                         |
 * +-------------------------------------------------------------------------+
 */

function Async ( arr, ondone )
{
    var asyncobj = this;
    for (var i=0; i< arr.length; i++)
        asyncobj.push(arr[i]);
    this.pointer = 0;
    this.ondone = ondone;
    this.nextElement = function() { return this[this.pointer+1]; };
    this.currentElement = function() { return this[this.pointer]; };

    this.start = function ( obj, ond ) {
        if (ond != null)
        {
            this.ondone = ond;
        }
        this.pointer = 0;
        this._control( obj );
    };

    this.continue = function ( obj ) {
        this.pointer++;
        this._control( obj );
    };

    this._control = function ( obj ) {
        console.log("_control", obj);
        if (this.pointer >= this.length)
        {
            if (typeof(this.ondone)=="function")
            {
                this.ondone( obj, this );
                return;
            }
            if (typeof(this.ondone)=="object") // instanceof gibt hier nur ärger
            {
                this.ondone.continue( obj );
                return;
            }
        }

        if (this[this.pointer]==null)
            return;
        if (typeof(this[this.pointer])=="function")
        {
            this.continue( this[this.pointer]( obj, this ) );
            return;
        }
        if (typeof(this[this.pointer])=="object") //auch hier gibt's Probleme mit instanceof
        {
            this[this.pointer].start( obj, this );
            return;
        }
        
    };

}

Async.prototype = new Array ();