Closed nornagon closed 1 year ago
Haha yeah, that's a bug, those promises should be internal only, and never leaked to user code.
Ah, I thought it might be! Makes sense, thanks :)
Hey, what version are you using? It looks like this was already fixed on f351e681, which was published as 7.14.1.
ah, i'm using 7.14.0. Seems to be fixed in 7.14.1, thanks!
I was tripped up by the fact that the
sizeCalculation
method is called first with aPromise
and then later with the resolved value when usingfetch()
.First here, calling with the Promise: https://github.com/isaacs/node-lru-cache/blob/724ee04e10a23a54c55b300e39e315cd75d8e0da/index.js#L758
and then here, calling with the value once the promise is resolved: https://github.com/isaacs/node-lru-cache/blob/724ee04e10a23a54c55b300e39e315cd75d8e0da/index.js#L731
and, further, sizeCalculation must return a valid size for the
Promise
, which is impossible in my use case (I don't know the size of the data before I fetch it!) and I suspect in many cases.I ended up making my
sizeCalculation
function return1
when the value it's passed isinstanceof Promise
, but that feels like quite a hack, and took me a while to arrive at.