Open michielbdejong opened 1 week ago
The following deno test passes unless you comment out one of the commented lines:
import BottleneckLight from "npm:bottleneck/light.js";
Deno.test("BottleneckLight", async () => {
const limiter = new BottleneckLight();
// limiter.schedule(() => { console.log('hi'); });
// await new Promise((resolve) => limiter.schedule(() => { resolve(null); }));
// await new Promise((resolve) => limiter.schedule(() => { resolve(null); console.log('hi'); }));
await new Promise((resolve) => limiter.schedule(() => { console.log('hi'); resolve(null); }));
});
Even with console.log('hi'); resolve(null);
in the schedule
callback it fails intermittently, about 20% of the time on my laptop.
A pretty consistent workaround seems to be the following:
import BottleneckLight from "npm:bottleneck/light.js";
Deno.test("BottleneckLight", async () => {
const limiter = new BottleneckLight();
await new Promise((resolve) => limiter.schedule(() => {
resolve(null);
}));
// work around https://github.com/SGrondin/bottleneck/issues/225
await new Promise(r => setTimeout(r, 0));
});
test.ts
:Deno.test("Bottleneck", async () => { const retryLimiter = new Bottleneck(); retryLimiter.schedule(async () => {}); });
Deno.test("BottleneckLight", async () => { const retryLimiter = new BottleneckLight(); retryLimiter.schedule(async () => {}); });