Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes the callback is not executed #31

Open
elhoyos opened this issue Jun 13, 2019 · 0 comments
Open

Sometimes the callback is not executed #31

elhoyos opened this issue Jun 13, 2019 · 0 comments

Comments

@elhoyos
Copy link
Contributor

elhoyos commented Jun 13, 2019

Using

// test.js
const request = require('request')
const cr = require('./lib/index')(request)
cr.setCacheDirectory('/tmp/cache');

const log = (i) => (err, response, body) => {
  if (err) throw err;
  const cached = !!response.headers["x-from-cache"];
  console.log(`${i}: ${response.statusCode}, ${cached}`);
};

cr({url: 'https://www.google.com', ttl: 10000}, log(1))
cr({url: 'https://www.google.com', ttl: 10000}, log(2))

If I execute it after a non-cached response, these executions sometimes will result in nothing printed in the screen, and only after the cache expires I'm able to see results back again.

$ node test.js
1: 200, false
2: 200, false
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
$ node test.js
1: 200, false
2: 200, false
$ node test.js
1: 200, true
2: 200, true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant