Accesing bounded kv namespaces

Hi, only this code allow me last_id values on my worker’s bounded BUY_ORDER KvNamespace. It’s really akward but it works.

async function handleRequest(request) {
const value = await last_id.get(“last_id”,‘text’)
await last_id.put(‘last_id’, Number(value) + 1)
if (value === null)
{ return new Response(“Value not found”, {status: 404})
}
return new Response(value)
}

Notice: You should call await last_id.get(“last_id”,‘text’) from inside an async function Handler(request), by starting a Promise that has to be fullfilled. Await do that, resuming execution after value are receive.