@@ -99,7 +99,7 @@ final class NativeSqliteDatabaseImpl extends SqliteDatabaseImpl {
9999 {Duration ? lockTimeout}) async {
100100 return _useConnection (
101101 writer: false ,
102- lockTimeout : lockTimeout,
102+ abortTrigger : lockTimeout? .asTimeout ,
103103 debugContext: 'readTransaction' ,
104104 (context) {
105105 return _transactionInLease (context, callback);
@@ -120,7 +120,7 @@ final class NativeSqliteDatabaseImpl extends SqliteDatabaseImpl {
120120 {Duration ? lockTimeout}) {
121121 return _useConnection (
122122 writer: true ,
123- lockTimeout : lockTimeout,
123+ abortTrigger : lockTimeout? .asTimeout ,
124124 debugContext: 'writeTransaction' ,
125125 (context) {
126126 return _transactionInLease (context, callback);
@@ -137,23 +137,27 @@ final class NativeSqliteDatabaseImpl extends SqliteDatabaseImpl {
137137 }
138138
139139 @override
140- Future <T > readLock <T >(Future <T > Function (SqliteReadContext tx) callback,
141- {Duration ? lockTimeout, String ? debugContext}) async {
140+ Future <T > abortableReadLock <T >(
141+ Future <T > Function (SqliteReadContext tx) callback,
142+ {Future <void >? abortTrigger,
143+ String ? debugContext}) async {
142144 return _useConnection (
143145 writer: false ,
144146 debugContext: debugContext ?? 'readLock' ,
145- lockTimeout : lockTimeout ,
147+ abortTrigger : abortTrigger ,
146148 (context) => ScopedReadContext .assumeReadLock (context, callback),
147149 );
148150 }
149151
150152 @override
151- Future <T > writeLock <T >(Future <T > Function (SqliteWriteContext tx) callback,
152- {Duration ? lockTimeout, String ? debugContext}) async {
153+ Future <T > abortableWriteLock <T >(
154+ Future <T > Function (SqliteWriteContext tx) callback,
155+ {Future <void >? abortTrigger,
156+ String ? debugContext}) async {
153157 return _useConnection (
154158 writer: true ,
155159 debugContext: debugContext ?? 'writeLock' ,
156- lockTimeout : lockTimeout ,
160+ abortTrigger : abortTrigger ,
157161 (context) => ScopedWriteContext .assumeWriteLock (context, callback),
158162 );
159163 }
@@ -162,14 +166,14 @@ final class NativeSqliteDatabaseImpl extends SqliteDatabaseImpl {
162166 Future <T > Function (_LeasedContext context) callback, {
163167 required bool writer,
164168 required String debugContext,
165- Duration ? lockTimeout ,
169+ Future < void > ? abortTrigger ,
166170 }) {
167- final timeout = lockTimeout? .asTimeout;
168171 return _runInLockContext (debugContext, () async {
169172 final pool = await _pool;
170173 final connection = await (writer
171- ? pool.writer (abortSignal: timeout)
172- : pool.reader (abortSignal: timeout));
174+ ? pool.writer (abortSignal: abortTrigger)
175+ : pool.reader (abortSignal: abortTrigger))
176+ .translateAbortExceptions (debugContext);
173177
174178 try {
175179 final context = _LeasedContext (
@@ -447,3 +451,10 @@ final class _LeasedContext extends UnscopedContext {
447451 return (db) => db.execute (sql);
448452 }
449453}
454+
455+ extension < T > on Future <T > {
456+ Future <T > translateAbortExceptions (String debugContext) {
457+ return onError <PoolAbortException >(
458+ (e, s) => Error .throwWithStackTrace (AbortException (debugContext), s));
459+ }
460+ }
0 commit comments