Skip to content

Sometimes the callback is not executed #31

@elhoyos

Description

@elhoyos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions