Skip to content

Commit 4f7cdce

Browse files
committed
[green] stop retired write continuations and observe pending errors
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent a223003 commit 4f7cdce

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎app/lib/pble/engine.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ class PbleEngine {
5959
}
6060
final _PendingRequest pending = _PendingRequest(cmd.opcode, timeout);
6161
_pending[cmd.id] = pending;
62+
// Disposal can reject this completion while an acknowledged write is
63+
// still pending. Observe errors now without replacing the original future
64+
// that the request later awaits (including its exact response/error).
65+
unawaited(
66+
pending.completer.future.then<void>(
67+
(_) {},
68+
onError: (Object _, StackTrace _) {},
69+
),
70+
);
6271
try {
6372
final List<Uint8List> packets = PbleFragmenter(
6473
mtu: _transport.mtu,
@@ -71,6 +80,12 @@ class PbleEngine {
7180
remaining,
7281
onTimeout: () => throw const _RequestDeadlineExpired(),
7382
);
83+
if (_disposed) {
84+
if (pending.completer.isCompleted) {
85+
return await pending.completer.future;
86+
}
87+
throw const PbleTimeoutException('engine disposed');
88+
}
7489
}
7590
if (pending.completer.isCompleted) {
7691
return await pending.completer.future;
@@ -109,6 +124,7 @@ class PbleEngine {
109124
).fragment(encodeFrame(cmd));
110125
for (final Uint8List packet in packets) {
111126
await _transport.send(packet, acknowledged: false);
127+
if (_disposed) throw const PbleTimeoutException('engine disposed');
112128
}
113129
}
114130

0 commit comments

Comments
 (0)