p0
01/01/2023, 5:06 AMsks
01/01/2023, 5:09 AMp0
01/01/2023, 5:10 AMsks
01/01/2023, 5:14 AMsks
01/01/2023, 5:47 AMp0
01/01/2023, 5:48 AMsks
01/01/2023, 5:49 AMp0
01/01/2023, 5:49 AMsks
01/01/2023, 6:04 AMp0
01/01/2023, 11:01 AMjavascript
export class Counter {
constructor(controller, env) {
this.storage = controller.storage;
}
async initialize() {
let stored = await this.storage.get("value");
this.value = stored || 0;
}
async fetch() {
if (!this.initializePromise) {
this.initializePromise = this.initialize();
}
await this.initializePromise;
++this.value;
await this.storage.put("value", this.value);
return new Response(this.value);
}
}
However, it isn't working as excepted. When I restart the dev server or wait a bit, the value resets back to 0. How do I fix this behavior?p0
01/01/2023, 11:03 AMp0
01/01/2023, 12:46 PMWalshy | Pages
01/01/2023, 1:06 PMp0
01/01/2023, 5:29 PMp0
01/01/2023, 5:32 PMp0
01/01/2023, 5:32 PMDanTheGoodman
01/01/2023, 6:04 PMDanTheGoodman
01/01/2023, 6:05 PMKai
01/01/2023, 6:24 PMp0
01/01/2023, 6:25 PMKai
01/01/2023, 6:25 PMKai
01/01/2023, 6:25 PMp0
01/01/2023, 6:31 PMp0
01/01/2023, 6:32 PMp0
01/01/2023, 6:33 PMKai
01/01/2023, 6:45 PMwrangler dev
for development, so idkjed
01/01/2023, 7:06 PMDanTheGoodman
01/01/2023, 7:42 PMjed
01/01/2023, 10:13 PMDanTheGoodman
01/01/2023, 10:13 PM