Hey Bruno et al.,
A developer who uses one of my Streamline projects emailed me with a really interesting issue: if he calls the Streamlined API from non-Streamline code, and a callback from his side throws an error, Streamline ends up re-calling that callback (this time with an error argument).
Here's a simple example -- plug this into the
online demo and and press "execute" to see the callback get called twice:
function foo(_) {
setTimeout(_, 1000);
return 'good';
}
foo(function (err, res) {
alert('called with err=' + err + ' and res=' + res);
throw new Error('foo');
});
This behavior took him by surprise because he (probably correctly) assumed that any errors his callback got were from *my* code and not his. And in this case, the errors thrown were AssertionErrors from test code.
His suggestion was that if a callback throws an error, Streamline should probably just re-throw it and let it propagate up to fail-fast/crash. That sounds like a great suggestion to me, but I'm not sure if you've thought about this deeper than we have and have a conscious reason for the current behavior. =)
What do you think? Thanks as always for the great work and consideration!
Cheers,
Aseem