* Returns a function that when executed, executes a lambda function, * but only executes it the number of times stated by howMany. * When done executing, it executes the completed function. Each callback * function receives the same parameters that are supplied to the * returned function eac
(howMany, lambda, completed)
| 203 | * @returns {Function} |
| 204 | */ |
| 205 | function countdown (howMany, lambda, completed) { |
| 206 | var result; |
| 207 | return function () { |
| 208 | if (--howMany >= 0 && lambda) result = lambda.apply(undef, arguments); |
| 209 | // we want ==, not <=, since some callers expect call-once functionality |
| 210 | if (howMany == 0 && completed) completed(result); |
| 211 | return result; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | core = { |
| 216 |