Sha256: 7287d41cefa8c790b6a3bd8a802614f93acf2fd0eaca3d2fc7b6fef0c5e2ce47

Contents?: true

Size: 991 Bytes

Versions: 508

Compression:

Stored size: 991 Bytes

Contents

# inflight

Add callbacks to requests in flight to avoid async duplication

## USAGE

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

// some request that does some stuff
function req(key, callback) {
  // key is any random string.  like a url or filename or whatever.
  //
  // will return either a falsey value, indicating that the
  // request for this key is already in flight, or a new callback
  // which when called will call all callbacks passed to inflightk
  // with the same key
  callback = inflight(key, callback)

  // If we got a falsey value back, then there's already a req going
  if (!callback) return

  // this is where you'd fetch the url or whatever
  // callback is also once()-ified, so it can safely be assigned
  // to multiple events etc.  First call wins.
  setTimeout(function() {
    callback(null, key)
  }, 100)
}

// only assigns a single setTimeout
// when it dings, all cbs get called
req('foo', cb1)
req('foo', cb2)
req('foo', cb3)
req('foo', cb4)
```

Version data entries

508 entries across 395 versions & 45 rubygems

Version Path
trusty-cms-6.3.1 node_modules/inflight/README.md
immosquare-cleaner-0.1.51 node_modules/inflight/README.md
boring_generators-0.15.0 tmp/templates/app_template/node_modules/inflight/README.md
immosquare-cleaner-0.1.50 node_modules/inflight/README.md
immosquare-cleaner-0.1.49 node_modules/inflight/README.md
immosquare-cleaner-0.1.48 node_modules/inflight/README.md
immosquare-cleaner-0.1.47 node_modules/inflight/README.md
immosquare-cleaner-0.1.46 node_modules/inflight/README.md
immosquare-cleaner-0.1.45 node_modules/inflight/README.md
immosquare-cleaner-0.1.44 node_modules/inflight/README.md
opal-1.8.3.rc1 stdlib/nodejs/node_modules/inflight/README.md
boring_generators-0.14.0 tmp/templates/app_template/node_modules/inflight/README.md
immosquare-cleaner-0.1.43 node_modules/inflight/README.md
immosquare-cleaner-0.1.42 node_modules/inflight/README.md
immosquare-cleaner-0.1.41 node_modules/inflight/README.md
immosquare-cleaner-0.1.40 node_modules/inflight/README.md
immosquare-cleaner-0.1.39 node_modules/inflight/README.md
immosquare-cleaner-0.1.38 node_modules/inflight/README.md
optimacms-0.1.61 spec/dummy/node_modules/inflight/README.md
boring_generators-0.13.0 tmp/templates/app_template/node_modules/inflight/README.md