"use strict";


const debug = require("debug")("controller1");


class Controller2 extends require("promise-command") {
    constructor(param) {
        super(param);
        this.started=[0,0];
      }
    errHandler(pos, err) {
//            debug("error",err,pos);
        if ( pos.diff[0] > 2){
          Object.assign(pos,{group:1});
        } else {
            Object.assign(pos,{group:0});
        }
          if (this.errcollector.size > 300) {
            return true;
        } else {
            return false;
        }

    }
    objHandler(pos, obj) { //add timing
        //debug("hier da",pos,obj);
        /*
    ; //store endresult in order of start like Promise.all
*/
    if ( pos.diff[0] > 2){
      Object.assign(pos,{group:1});

    } else {
          Object.assign(pos,{group:0});
    }
    }
    endHandler() {
        if (this.errcollector.size > 300) { //throw with error
            debug("finished with error %d", this.errcollector.size);
            this.emit("ende", [...this.errcollector]);
        } else { // return the array of results
            debug("finished with gen");
            this.emit("ende", null, []);
        }

    }

    makeIteratorInpG (array,dir){
       var nextIndex = 0;

       return {
          next: function(){
            for (;;){
            if ( nextIndex < array.length){
              const value = array[nextIndex++];
                if ( value && "input" in value &&
              (dir === value.group ) ){
                  return { value ,done: false};
                }
            } else {
              return     {done: true};
            }

        }
       }
   };
  }

    *
    dataGenerator(res) {


let la;

const first=  yield* this.startAll(this.makeIterator(res));

let zahl0=0,zahl1=0;
for (let i=0; i< first.length;i++){
  if ( first[i] && first[i].group === 0){
      zahl0++;
  } else    if ( first[i] && first[i].group === 1){
    zahl1++;
  }
}
debug("start wiederhol mit %d %d %d",first.length,zahl0,zahl1);

let iter =  [   this.makeIteratorInpG(first,0),     this.makeIteratorInpG(first,1)];

for(;  ;){
    if ( !la){
      la ={group: 0};
    }else {
          first.push(la);
      }

      for ( let i=0;i< 2;i++){
      const next = iter[la.group||0].next();
//debug("ne",next,la);
        if ( next.done){
         if (la.group ){
           la ={group: 0};
         } else {
           la ={group: 1};
         }

        } else{
              this.started[la.group||0]++;
              la = yield* this.startOne(this.fun, next.value.input);
              delete next.value.input;
          break;
        }

      }
    }


/*
  let next=first;
  for (let i = 0; i < 30; i++) {

        //  yield* this.waiter(10000 - (moment.now("X") - now));
      debug("itermediatore %d %d",i, next.length);
      next=  yield* this.startAll(this.makeIteratorInp(next));

  }
*/

    }
}

module.exports = Controller2;

@@ -1435,24 +1435,10 @@
 e &&
-%0A
   
-            (
 dir 
@@ -1457,13 +1457,55 @@
 oup 
-)
  )%7B%0A
+                delete array%5BnextIndex++%5D;%0A
     
@@ -2199,24 +2199,126 @@
 la);%0A      %7D
+%0A      if ( this.open.size %3E= this.parallel  )%7B%0A         la = yield Promise.resolve();%0A      %7D  else %7B
 %0A%0A      for 
@@ -2672,47 +2672,8 @@
 t);%0A
-              delete next.value.input;%0A
     
@@ -2691,24 +2691,25 @@
 ;%0A        %7D%0A
+%7D
 %0A      %7D%0A   

Update controller2.js