Sha256: c9a8e9124c9773972452eb7edd85b3f1cee2a55744e568e55416c4782f6dc74b

Contents?: true

Size: 842 Bytes

Versions: 7

Compression:

Stored size: 842 Bytes

Contents

# once

Only call a function once.

## usage

```javascript
var once = require('once')

function load (file, cb) {
  cb = once(cb)
  loader.load('file')
  loader.once('load', cb)
  loader.once('error', cb)
}
```

Or add to the Function.prototype in a responsible way:

```javascript
// only has to be done once
require('once').proto()

function load (file, cb) {
  cb = cb.once()
  loader.load('file')
  loader.once('load', cb)
  loader.once('error', cb)
}
```

Ironically, the prototype feature makes this module twice as
complicated as necessary.

To check whether you function has been called, use `fn.called`:

```javascript
var once = require('once')

function load (cb) {
  cb = once(cb)
  var stream = createStream()
  stream.once('data', cb)
  stream.once('end', function () {
    if (!cb.called) cb(new Error('not found'))
  })
}
```

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md
entangled-0.0.12 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md
entangled-0.0.11 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md
entangled-0.0.10 spec/dummy/public/node_modules/bower/node_modules/tar-fs/node_modules/pump/node_modules/once/README.md