File tree Expand file tree Collapse file tree 3 files changed +6
-5
lines changed Expand file tree Collapse file tree 3 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,8 @@ void main() async {
65
65
// 1. Atomic persistence (all updates are either applied or rolled back).
66
66
// 2. Improved throughput.
67
67
await db.writeTransaction((tx) async {
68
- await db .execute('INSERT INTO test_data(data) values(?)', ['Test3']);
69
- await db .execute('INSERT INTO test_data(data) values(?)', ['Test4']);
68
+ await tx .execute('INSERT INTO test_data(data) values(?)', ['Test3']);
69
+ await tx .execute('INSERT INTO test_data(data) values(?)', ['Test4']);
70
70
});
71
71
72
72
await db.close();
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ void main() async {
29
29
// 1. Atomic persistence (all updates are either applied or rolled back).
30
30
// 2. Improved throughput.
31
31
await db.writeTransaction ((tx) async {
32
- await db .execute ('INSERT INTO test_data(data) values(?)' , ['Test3' ]);
33
- await db .execute ('INSERT INTO test_data(data) values(?)' , ['Test4' ]);
32
+ await tx .execute ('INSERT INTO test_data(data) values(?)' , ['Test3' ]);
33
+ await tx .execute ('INSERT INTO test_data(data) values(?)' , ['Test4' ]);
34
34
});
35
35
36
36
// Close database to release resources
Original file line number Diff line number Diff line change @@ -175,6 +175,7 @@ void main() {
175
175
// Note: In highly concurrent cases, it could exhaust the connection pool and cause a deadlock.
176
176
177
177
await db.writeTransaction ((tx) async {
178
+ // Use the parent zone to avoid the "recursive lock" error.
178
179
await zone.fork ().run (() async {
179
180
await db.getAll ('SELECT * FROM test_data' );
180
181
});
@@ -192,7 +193,7 @@ void main() {
192
193
});
193
194
});
194
195
195
- // This would deadlock, since it shares a global write lock.
196
+ // Note: This would deadlock, since it shares a global write lock.
196
197
// await db.writeTransaction((tx) async {
197
198
// await zone.fork().run(() async {
198
199
// await db.execute('SELECT * FROM test_data');
You can’t perform that action at this time.
0 commit comments