```

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?
Z
zegevlier361d ago
That seems right, is it not doing what you expect it to do?
D
DaniFoldi361d ago
I'd await the setAlarm and the deleteAll calls as well, just to be sure they complete