File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,15 @@ export class MyDurableObject extends DurableObject {
4141
4242 // It's common to run schema migrations or table creations in the constructor,
4343 // wrapped in blockConcurrencyWhile to ensure they complete before other operations.
44- this .ctx .blockConcurrencyWhile (async () => {
45- await this .initializeDB ();
44+ // Operations inside blockConcurrencyWhile are synchronous with respect to DO storage.
45+ this .ctx .blockConcurrencyWhile (() => {
46+ this .initializeDB ();
4647 });
4748 }
4849
49- async initializeDB() {
50+ initializeDB() {
5051 // Example: Create table if it doesn't exist
51- // Note: .execute() is synchronous for DOQB, but blockConcurrencyWhile expects a Promise
52+ // .execute() is synchronous for DOQB.
5253 this .#qb .createTable ({
5354 tableName: ' items' , // Example table
5455 ifNotExists: true ,
@@ -95,7 +96,8 @@ export class MyDurableObject extends DurableObject {
9596 super (state , env );
9697 this .#qb = new DOQB (this .storage .sql );
9798
98- this .ctx .blockConcurrencyWhile (async () => {
99+ // Operations inside blockConcurrencyWhile are synchronous with respect to DO storage.
100+ this .ctx .blockConcurrencyWhile (() => {
99101 // Create table (if not exists) - good practice in constructor
100102 this .#qb .createTable ({
101103 tableName: ' items' ,
Original file line number Diff line number Diff line change @@ -89,16 +89,17 @@ export class MyDurableObject extends DurableObject {
8989 super (state , env );
9090
9191 this .#qb = new DOQB (this .ctx .storage .sql );
92- void this .ctx .blockConcurrencyWhile (async () => {
92+ void this .ctx .blockConcurrencyWhile (() => {
9393 // Assuming 'migrations' is an array of Migration objects defined elsewhere
9494 const migrationBuilder = this .#qb .migrations ({ migrations });
95- await migrationBuilder .apply (); // Ensure apply is awaited
95+ migrationBuilder .apply (); // Operations within blockConcurrencyWhile are synchronous
9696 });
9797 }
9898
99- async getUsers(): Promise < Array <object > > {
99+ getUsers(): Array <object > {
100100 // Example method, ensure migrations are applied before accessing tables
101- return this .#qb .select (' users' ).all ().results
101+ // Operations within Durable Objects are generally synchronous after the initial setup.
102+ return this .#qb .select (' users' ).all ().results ;
102103 }
103104}
104105```
You can’t perform that action at this time.
0 commit comments