describe('promiseAllStepN', function(){ describe('3 tasks, and cucurrent is 2', function(){ let tasks; beforeEach(function(){ tasks = range(3).map(x=>sinon.stub()) }) describe('1 is finish', function(){ it('will kickoff the third task', function(done){ tasks[0].returns(Promise.resolve(0)) let task2 = tasks[2] tasks[1].returns(new Promise(resolve=>setTimeout(()=>{ expect(task2.called).to.be.equal(true) resolve(1) done() }, 1000))) tasks[2].returns(Promise.resolve(2)) return Promise.allConcurrent(2)(tasks).then(x=>console.log(x)) }) }) }) describe('10 tasks, and cucurrent is 3', function(){ let tasks; beforeEach(function(){ tasks = range(10).map(x=>sinon.stub()) }) describe('1st is finish but 2nd stuck', function(){ it.only('final task will run before 2nd', function(done){ tasks.forEach((task,index) => task.returns(Promise.resolve(index))) let task10 = tasks[9] tasks[1].returns(new Promise(resolve=>setTimeout(()=>{ expect(task10.called).to.be.equal(true) resolve(1) done() }, 1000))) return Promise.allConcurrent(2)(tasks).then(x=>console.log(x)) }) }) }) })