```

const MINUTES = 60 * 1000

export class NanoID {
constructor(state, env) {
this.state = state
}

async fetch() {
let value = await this.state.storage.get("value")
if (!value) {
value = nanoid()
await this.state.storage.put("value", value)
this.storage.setAlarm(Date.now() + 2 * MINUTES)
}
return new Response(value)
}

async alarm() {
this.state.storage.deleteAll()
}
}
const MINUTES = 60 * 1000

export class NanoID {
constructor(state, env) {
this.state = state
}

async fetch() {
let value = await this.state.storage.get("value")
if (!value) {
value = nanoid()
await this.state.storage.put("value", value)
this.storage.setAlarm(Date.now() + 2 * MINUTES)
}
return new Response(value)
}

async alarm() {
this.state.storage.deleteAll()
}
}
Does this look okay?
2 Replies
zegevlier
zegevlier2y ago
That seems right, is it not doing what you expect it to do?
DaniFoldi
DaniFoldi2y ago
I'd await the setAlarm and the deleteAll calls as well, just to be sure they complete
Want results from more Discord servers?
Add your server