medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.74k stars 61 forks source link

max and maxAge in combination with async: true lead blocking of event loop #9

Closed jaclar closed 11 years ago

jaclar commented 11 years ago

Consider the following example:

var memoize = require("memoizee");

var mem = memoize(function (returnError, callback) {
    setTimeout(function () {
        if (returnError) {
            callback(new Error("My Error"));
        } else {
            callback(null, true);
        }
    }, 50);
}, {
    async: true,
    maxAge: 50,
    max: 10,
    preFetch: false
});

mem(true, function (err, value) {
    if (err) {
        console.log("Error: " + err.message);
    } else {
        console.log("Value: " + value);
    }
});

mem(false, function (err, value) {
    if (err) {
        console.log("Error: " + err.message);
    } else {
        console.log("Value: " + value);
    }
});

console.log("Let's wait a bit...");

setTimeout(function () {
    console.log("Enough waiting!");
    process.exit(0);
}, 30000);

This will send memoizee into an infinite loop.

additional information

$ node --version
v0.10.20

$ npm ls
└─┬ memoizee@0.2.5
  ├── es5-ext@0.9.2
  ├── event-emitter@0.2.2
  └── next-tick@0.1.0
medikoo commented 11 years ago

Thanks. There was a bug in logic that propagates internal events (case of erroneous async call).

Fixed and published as v0.2.6