3 Add callbacks to requests in flight to avoid async duplication
8 var inflight = require('inflight')
10 // some request that does some stuff
11 function req(key, callback) {
12 // key is any random string. like a url or filename or whatever.
14 // will return either a falsey value, indicating that the
15 // request for this key is already in flight, or a new callback
16 // which when called will call all callbacks passed to inflightk
18 callback = inflight(key, callback)
20 // If we got a falsey value back, then there's already a req going
23 // this is where you'd fetch the url or whatever
24 // callback is also once()-ified, so it can safely be assigned
25 // to multiple events etc. First call wins.
26 setTimeout(function() {
31 // only assigns a single setTimeout
32 // when it dings, all cbs get called