Closed fraxken closed 3 years ago
The current .has(key) method has a major flaw because the method return true for a key but it doesn't mean the key will still exist later in time.
.has(key)
true
In the following example we show the problem (in this example we imagine that "key" already exist in the Map).
const test = new TimeMap(1_000); async function doTheWork() { console.log(test.has("key")); // true await new Promise((resolve) => setImmediate(resolve)); console.log(test.get("key")); // ?? } doTheWork().catch(console.error);
This is very problematic because in a purely asynchronous code there can be several ticks between a .has and a .get!
Like the get method we should implement a refreshTimestamp option on .has().
.has()
It will guarantee that the key exists for 1_000 ms.
1_000
The current
.has(key)
method has a major flaw because the method returntrue
for a key but it doesn't mean the key will still exist later in time.In the following example we show the problem (in this example we imagine that "key" already exist in the Map).
This is very problematic because in a purely asynchronous code there can be several ticks between a .has and a .get!
Like the get method we should implement a refreshTimestamp option on
.has()
.It will guarantee that the key exists for
1_000
ms.