does `runDurableObjectAlarm()` return `true` or a similar value?
does
runDurableObjectAlarm() return true or a similar value?runDurableObjectAlarm()while (true) what about while (ran)? Declare ran as true before the first runawait to be consistent with the API that you need to await a Promise. The underlying behavior doesn't change.await of a promise will be more confused, rather than having to read all the DO docs to figure out that it doesn't matter.blockConcurrencyWhile when applying migration in constructor, and also I can put the entire migration into a transactionSync to prevent the rare event that migrations succeeded but writing migration number fails.transaction()? blockConcurrencyWhile has a different purpose than sync/async.storage.get/storage.set's implementations are sync, because applyMigration is async, .then puts continuation in the next event loop, so the log order will be before -> after -> initialized. I haven't tested it but unless DO has a different behavior to regular JS, that should be the case.this.someState is still undefined) by the end of current event loop. I don't know if DO is able to process messages in the same event loop as the one doing the construction, but if that's true, then that's an issue.blockConcurrencyWhile is a workaround, but if we had an actual sync API, we wouldn't even need it.this.someState = -1 before the call to ctx.blockConcurrencyWhile(...) and then the property won't be considered optional.blockConcurrencyWhile at all, because applyMigrations can just be sync.storage.get/storage.set is async, you also couldn't do:await puts continuation in the next event loop, by which point transactionSync already exited.transaction(...) which is async. Anyway, we seem to be going in circles transaction with SQLite?When using the SQLite-backed storage engine, the txn object is obsolete. Any storage operations performed directly on the ctx.storage object, including SQL queries using ctx.storage.sql.exec(), will be considered part of the transaction.You can use both APIs, KV and SQL, inside an SQLite DO.
transactionSync with SQLite.SELECT name FROM sqlite_master WHERE type='table' AND name=?;async function applyMigrations(storage: DurableObjectStorage) {
await storage.get(...)
// Do migration stuffs
await storage.set(...)
}class MyDO extends DurableObject {
someState!: number
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env)
console.log('before')
applyMigrations(ctx.storage).then(() => {
this.someState = 42
console.log('initialized')
})
console.log('after')
}
}async function applyMigrations(storage: DurableObjectStorage) {
storage.transactionSync(async () => {
const currentMigration = await storage.get(...)
// Do migration stuffs
await storage.set(...)
})
}while (true)while (ran)ran