api-promise
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,20 +7,2 @@ 'use strict' | ||
const dnsCache = {} | ||
const lookup = (host, cb) => { | ||
if (dnsCache[host]) { | ||
cb(null, dnsCache[host]) | ||
} else { | ||
dns.lookup(host, { hints: dns.ADDRCONFIG }, (err, address) => { | ||
if (err) { | ||
cb(err) | ||
} else { | ||
dnsCache[host] = address | ||
setTimeout(() => { delete dnsCache[host] }, 3e4) | ||
cb(null, dnsCache[host]) | ||
} | ||
}) | ||
} | ||
} | ||
module.exports = (hostname, token, headers, options) => { | ||
@@ -58,1 +40,29 @@ headers = Object.assign( | ||
} | ||
const dnsCache = {} | ||
function lookup (host, options, cb) { | ||
if (!cb) { | ||
cb = options | ||
options = null | ||
} | ||
if (dnsCache[host] && dnsCache[host][2] > +new Date() - 6e4) { | ||
clearTimeout(dnsCache[host][3]) | ||
dnsCache[host][3] = setTimeout(() => { delete dnsCache[host] }, 500) | ||
cb(null, dnsCache[host][0], dnsCache[host][1]) | ||
} else { | ||
if (dnsCache[host]) { | ||
clearTimeout(dnsCache[host][3]) | ||
delete dnsCache[host] | ||
} | ||
dns.lookup(host, options, (err, ip, type) => { | ||
if (err) { | ||
cb(err) | ||
} else { | ||
dnsCache[host] = [ip, type, +new Date()] | ||
dnsCache[host][3] = setTimeout(() => { delete dnsCache[host] }, 500) | ||
cb(null, dnsCache[host][0], dnsCache[host][1]) | ||
} | ||
}) | ||
} | ||
} |
{ | ||
"name": "api-promise", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An observable to run async tasks in parallel with a concurrency limit", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -17,1 +17,14 @@ # api-promise | ||
## Usage | ||
```js | ||
const ap = require('api-promise') | ||
const github = ap('api.github.com', 'GITHUB-TOKEN') | ||
github('POST', '/some/api/path', { param: 'value' }) | ||
.then(res => { | ||
// do something with the response | ||
}) | ||
.catch(err => { | ||
// do something with the error | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5857
81
30