maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
727 stars 58 forks source link

Overused deferral warning #126

Closed corpix closed 10 years ago

corpix commented 10 years ago

I have this test code(mocha):

it 'should return `MethodExistsError` if method with same name was already defined', (done) ->                                                                                                                                                                       
    methodName = 'test'                                                                                                                                                                                                                                              
    method = (->)                                                                                                                                                                                                                                                    
    await service.defineMethod(methodName, method, defer(err, res))                                                                                                                                                                                                  
    assert.equal(err, null)                                                                                                                                                                                                                                          
    assert.equal(res, true)                                                                                                                                                                                                                                          
    await service.defineMethod(methodName, method, defer(err))                                                                                                                                                                                                       
    assert.equal(err instanceof Rpc.MethodExistsError, true)                                                                                                                                                                                                         
    done()

That runs with ./node_modules/.bin/mocha --compilers iced:iced-coffee-script/register --colors --recursive tests and writes this warning to stderr:

ICED warning: overused deferral at <anonymous> (/home/vagrant/Code/metatron-io-core/tests/rpc.RpcService.iced:77)

Whats could be wrong with this code? My iced-coffee-script version:

$ npm ls iced-coffee-script
metatron-io-core@0.0.0 /home/vagrant/Code/metatron-io-core
└── iced-coffee-script@1.7.1-f
maxtaco commented 10 years ago

I don't know what service.defineMethod does, but seems as if it calls its callback more than once, which is a no-no.

corpix commented 10 years ago

@maxtaco, wow! Thats my fault. Forgot to return after passing error into callback. Thank you

malgorithms commented 10 years ago

another reason why I love iced-coffee is that it helps you catch bugs like this. I've made the same mistake...