Browse Source

Refactor createEndpointMethod to not be wrapped in a promise

pull/14/head
Luke Childs 8 years ago
parent
commit
a17b03cf46
  1. 8
      src/index.js

8
src/index.js

@ -53,7 +53,7 @@ class Onionoo {
// Returns a function to make requests to a given endpoint
createEndpointMethod (endpoint) {
return args => new Promise((resolve, reject) => {
return args => {
// Build query string (don't encode ':' for search filters)
const qs = querystring.encode(args).replace(/%3A/g, ':')
@ -62,11 +62,11 @@ class Onionoo {
// Check for url in cache
if (this.options.cache) {
this.options.cache.get(url).then(cachedResult => resolve(cachedResult || this.makeRequest(url)))
return this.options.cache.get(url).then(cachedResult => cachedResult || this.makeRequest(url))
} else {
resolve(this.makeRequest(url))
return this.makeRequest(url)
}
})
}
}
// Returns a promise for a request

Loading…
Cancel
Save