CB-12003 updated node_modules

This commit is contained in:
Steve Gill
2016-10-17 10:50:30 -07:00
parent 2e37d2c253
commit 0b710a86a9
36 changed files with 602 additions and 299 deletions
+28
View File
@@ -49,3 +49,31 @@ function load (cb) {
})
}
```
## `once.strict(func)`
Throw an error if the function is called twice.
Some functions are expected to be called only once. Using `once` for them would
potentially hide logical errors.
In the example below, the `greet` function has to call the callback only once:
```javascript
function greet (name, cb) {
// return is missing from the if statement
// when no name is passed, the callback is called twice
if (!name) cb('Hello anonymous')
cb('Hello ' + name)
}
function log (msg) {
console.log(msg)
}
// this will print 'Hello anonymous' but the logical error will be missed
greet(null, once(msg))
// once.strict will print 'Hello anonymous' and throw an error when the callback will be called the second time
greet(null, once.strict(msg))
```