PokeAPI / pokedex-promise-v2

An easy way to use pokeapi v2 with promises in node.js
MIT License
516 stars 91 forks source link

Connection doesn't close after request is made #20

Closed nicolaifsf closed 7 years ago

nicolaifsf commented 7 years ago

Function calls do not end after a request is made.

When using the example, calling P.getPokemonByName() and logging to console works, however it hangs after that.

Naramsim commented 7 years ago

Hi @nicolaifsf, you are partially correct. The process hangs on, but the connection is closed. Our wrapper caches the results in the RAM, thanks to memory-cache, which by default keeps alive the process.

I tried building this wrapper without memory-cache and it correctly quits.

Maybe we could implement something that, if the cacheLimit is zero, doesn't invoke memory-cache so the process quits normally.

Naramsim commented 7 years ago

Got it! If you set for example a cacheLimit of 3 seconds. The wrapper will maintain the cache only for 3 seconds and then exits.

var options = {
    protocol: 'http',
    hostName: 'pokeapi.co',
    versionPath: '/api/v2/',
    timeout: 10000,
        cacheLimit: 3 * 1000
}
nicolaifsf commented 7 years ago

That solved problem! Thank you so much! 👍