Unsmart | Tech debt
01/22/2023, 7:07 PMts
const val = await storage.get('something')
await someCode()
await storage.put('something', val + 1)
Could have issuesGiggiux
01/22/2023, 7:09 PMput
in a wrapper async
functionUnsmart | Tech debt
01/22/2023, 7:10 PMGiggiux
01/22/2023, 7:10 PMput
notice, it would seems as it would be "smarter" and understand that the concurrency between the get
and put
should be avoided and/or let the following `get`s wait for the last put
of the previous operationGiggiux
01/22/2023, 7:11 PMawait someCode()
between blockConcurrencyWhile
Unsmart | Tech debt
01/22/2023, 7:17 PMts
this.app.post('/test/concurrency', async c => {
console.log('Received request in DO', new Date().toISOString())
await this.state.blockConcurrencyWhile(() => this.timeout(10000))
console.log('Finished waiting in DO', new Date().toISOString())
return c.json({ timeout: true })
})
With 2 concurrent requests made both requests take 20s to return, and the console.log for finished was put into the 2nd request for bothGiggiux
01/22/2023, 7:24 PMblockConcurrencyWhile
returns a promise, but... do you need to await it to make it work? I am (mistakenly probably) using it without the await
and seems to work exactly as expected
Regarding the logs... Yeah it's pretty strange behaviourUnsmart | Tech debt
01/22/2023, 7:26 PMUnsmart | Tech debt
01/22/2023, 7:28 PMUnsmart | Tech debt
01/22/2023, 7:28 PMUnsmart | Tech debt
01/22/2023, 7:29 PMUnsmart | Tech debt
01/22/2023, 7:33 PMts
this.app.post('/test/concurrency', async c => {
this.state.blockConcurrencyWhile(() => {
console.log('Received request in DO', new Date().toISOString())
await this.timeout(10000)
console.log('Finished waiting in DO', new Date().toISOString())
})
return c.json({ timeout: true })
})
Giggiux
01/22/2023, 7:36 PMUnsmart | Tech debt
01/22/2023, 7:36 PMUnsmart | Tech debt
01/22/2023, 7:40 PMts
export class TestDO implements DurableObject {
private app = new Hono<Bindings>()
constructor(private state: DurableObjectState, private env: Bindings) {
this.app.get('/', async c => c.text('Hello!'))
this.app.post('/test/concurrency', async c => {
this.state.blockConcurrencyWhile(async () => {
console.log('Received request in DO', new Date().toISOString())
await scheduler.wait(10000)
console.log('Finished waiting in DO', new Date().toISOString())
})
return c.json({ timeout: true })
})
}
async fetch(request: Request) {
return this.app.fetch(request, this.env)
}
}
Giggiux
01/22/2023, 7:40 PMsteeldragon
01/23/2023, 6:03 PMname
supposed to be in DurableObjectId
, is it supposed to be the name that i generated the id from?HardAtWork
01/23/2023, 6:06 PMsteeldragon
01/23/2023, 6:06 PMHardAtWork
01/23/2023, 6:08 PMHardAtWork
01/23/2023, 6:08 PMsteeldragon
01/23/2023, 6:09 PMHardAtWork
01/23/2023, 6:11 PMnewUniqueId()
), so I'm not 100% how it is generated/persisted.Unsmart | Tech debt
01/23/2023, 6:12 PMsteeldragon
01/23/2023, 6:13 PMckoeninger
01/23/2023, 7:41 PMckoeninger
01/23/2023, 7:41 PMckoeninger
01/23/2023, 7:42 PMckoeninger
01/23/2023, 7:43 PMehesp
01/24/2023, 1:24 PMaddEventListener
, do I access the environment from global...
export interface Env {
MY_DURABLE_OBJECT: DurableObjectNamespace;
}
addEventListener('fetch', (event) => {
MY_DURABLE_OBJECT.foo
});
How do I correctly handle that for TypeScript? is this the correct way?
declare global {
MY_DURABLE_OBJECT: DurableObjectNamespace;
}