@@ -13,6 +13,9 @@ abstract class Mutex {
1313 /// timeout is a timeout for acquiring the lock, not for the callback
1414 Future <T > lock <T >(Future <T > Function () callback, {Duration ? timeout});
1515
16+ /// Release resources used by the Mutex.
17+ ///
18+ /// Subsequent calls to [lock] may fail, or may never call the callback.
1619 Future <void > close ();
1720}
1821
@@ -32,7 +35,7 @@ class SimpleMutex implements Mutex {
3235
3336 bool get locked => last != null ;
3437
35- SharedMutexServer ? _shared;
38+ _SharedMutexServer ? _shared;
3639
3740 @override
3841 Future <T > lock <T >(Future <T > Function () callback, {Duration ? timeout}) async {
@@ -99,15 +102,15 @@ class SimpleMutex implements Mutex {
99102
100103 /// Get a serialized instance that can be passed over to a different isolate.
101104 SerializedMutex get shared {
102- _shared ?? = SharedMutexServer ._withMutex (this );
105+ _shared ?? = _SharedMutexServer ._withMutex (this );
103106 return _shared! .serialized;
104107 }
105108}
106109
107110/// Serialized version of a Mutex, can be passed over to different isolates.
108- /// Use [open] to get a Mutex instance.
111+ /// Use [open] to get a [SharedMutex] instance.
109112///
110- /// Uses [SendPort] to communicate with the source mutex.
113+ /// Uses a [SendPort] to communicate with the source mutex.
111114class SerializedMutex {
112115 final SerializedPortClient client;
113116
@@ -176,15 +179,15 @@ class SharedMutex implements Mutex {
176179 }
177180}
178181
179- /// Like Mutex, but can be coped across Isolates .
180- class SharedMutexServer {
182+ /// Manages a [SerializedMutex] , allowing a [Mutex] to be shared across isolates .
183+ class _SharedMutexServer {
181184 Completer ? unlock;
182185 late final SerializedMutex serialized;
183186 final Mutex mutex;
184187
185188 late final PortServer server;
186189
187- SharedMutexServer ._withMutex (this .mutex) {
190+ _SharedMutexServer ._withMutex (this .mutex) {
188191 server = PortServer ((Object ? arg) async {
189192 return await _handle (arg);
190193 });
0 commit comments