| OLD | NEW |
| (Empty) | |
| 1 var async = require('../lib/async'); |
| 2 var expect = require('chai').expect; |
| 3 var isBrowser = require('./support/is_browser'); |
| 4 |
| 5 describe('forever', function(){ |
| 6 context('function is asynchronous', function(){ |
| 7 it('executes the function over and over until it yields an error', funct
ion(done){ |
| 8 var counter = 0; |
| 9 function addOne(callback) { |
| 10 counter++; |
| 11 if (counter === 50) { |
| 12 return callback('too big!'); |
| 13 } |
| 14 async.setImmediate(function () { |
| 15 callback(); |
| 16 }); |
| 17 } |
| 18 async.forever(addOne, function (err) { |
| 19 expect(err).to.eql('too big!'); |
| 20 expect(counter).to.eql(50); |
| 21 done(); |
| 22 }); |
| 23 }); |
| 24 }); |
| 25 |
| 26 context('function is synchronous', function(){ |
| 27 it('does not cause a stack overflow', function(done){ |
| 28 if (isBrowser()) return done(); // this will take forever in a brows
er |
| 29 var counter = 0; |
| 30 function addOne(callback) { |
| 31 counter++; |
| 32 if (counter === 50000) { // needs to be huge to potentially over
flow stack in node |
| 33 return callback('too big!'); |
| 34 } |
| 35 callback(); |
| 36 } |
| 37 async.forever(addOne, function (err) { |
| 38 expect(err).to.eql('too big!'); |
| 39 expect(counter).to.eql(50000); |
| 40 done(); |
| 41 }); |
| 42 }); |
| 43 }); |
| 44 }); |
| OLD | NEW |