File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import 'package:sqlite_async/src/common/mutex.dart';
7
7
import 'package:sqlite_async/src/common/port_channel.dart' ;
8
8
9
9
abstract class MutexImpl implements Mutex {
10
- factory MutexImpl () {
10
+ factory MutexImpl ({ String ? identifier} ) {
11
11
return SimpleMutex ();
12
12
}
13
13
}
@@ -19,12 +19,13 @@ class SimpleMutex implements MutexImpl {
19
19
// Adapted from https://github.com/tekartik/synchronized.dart/blob/master/synchronized/lib/src/basic_lock.dart
20
20
21
21
Future <dynamic >? last;
22
+ String ? identifier;
22
23
23
24
// Hack to make sure the Mutex is not copied to another isolate.
24
25
// ignore: unused_field
25
26
final Finalizer _f = Finalizer ((_) {});
26
27
27
- SimpleMutex ();
28
+ SimpleMutex ({ this .identifier} );
28
29
29
30
bool get locked => last != null ;
30
31
Original file line number Diff line number Diff line change @@ -58,7 +58,8 @@ class MutexImpl implements Mutex {
58
58
Future .delayed (timeout, () {
59
59
isTimedOut = true ;
60
60
if (lockObtained == false ) {
61
- completer.completeError (LockError ('Timeout reached' ));
61
+ completer.completeError (
62
+ TimeoutException ('Failed to acquire lock' , timeout));
62
63
}
63
64
});
64
65
}
@@ -109,7 +110,8 @@ class MutexImpl implements Mutex {
109
110
if (lockAcquired == true ) {
110
111
return ;
111
112
}
112
- gotLock.completeError (LockError ('Timeout reached' ));
113
+ gotLock
114
+ .completeError (TimeoutException ('Failed to acquire lock' , timeout));
113
115
controller.abort ('Timeout' .toJS);
114
116
});
115
117
}
Original file line number Diff line number Diff line change
1
+ import 'dart:async' ;
1
2
import 'dart:math' ;
2
3
3
4
import 'package:sqlite_async/sqlite_async.dart' ;
@@ -41,7 +42,9 @@ void main() {
41
42
m.lock (() async {
42
43
print ('This should not get executed' );
43
44
}, timeout: Duration (milliseconds: 200 )),
44
- throwsA ((e) => e is LockError && e.message.contains ('Timeout' )));
45
+ throwsA ((e) =>
46
+ e is TimeoutException &&
47
+ e.message! .contains ('Failed to acquire lock' )));
45
48
});
46
49
47
50
test ('In-time timeout should function normally' , () async {
You can’t perform that action at this time.
0 commit comments