Skip to content

Commit 8aad9b4

Browse files
authored
fix: CancelListenFunc should have a declared return type (#908)
`CancelListenFunc` should have a declared return type, otherwise `dynamic` will start trickling into the users' of this code bases.
1 parent 845c0a1 commit 8aad9b4

File tree

6 files changed

+8
-16
lines changed

6 files changed

+8
-16
lines changed

lib/src/data_stream/stream_writer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../utils.dart';
1111

1212
class BaseStreamWriter<T, InfoType extends BaseStreamInfo> {
1313
final StreamWriter<T> writableStream;
14-
Function()? onClose;
14+
Future<void> Function()? onClose;
1515

1616
final InfoType info;
1717

@@ -23,7 +23,7 @@ class BaseStreamWriter<T, InfoType extends BaseStreamInfo> {
2323

2424
Future<void> close() async {
2525
await writableStream.close();
26-
onClose?.call();
26+
await onClose?.call();
2727
}
2828
}
2929

lib/src/managers/event.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ abstract class EventsListenable<T> extends Disposable {
185185
// cast to E
186186
await then(event);
187187
// cancel after 1 event
188-
cancelFunc?.call();
188+
await cancelFunc?.call();
189189
});
190190
return cancelFunc;
191191
}

lib/src/participant/local.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,13 +1218,7 @@ extension DataStreamParticipantMethods on LocalParticipant {
12181218

12191219
final cancelFun = room.engine.events.once<EngineClosingEvent>((_) => onEngineClose);
12201220

1221-
final writer = TextStreamWriter(
1222-
writableStream: writableStream,
1223-
info: info,
1224-
onClose: () {
1225-
cancelFun?.call();
1226-
},
1227-
);
1221+
final writer = TextStreamWriter(writableStream: writableStream, info: info, onClose: cancelFun);
12281222

12291223
return writer;
12301224
}
@@ -1320,9 +1314,7 @@ extension DataStreamParticipantMethods on LocalParticipant {
13201314
final byteWriter = ByteStreamWriter(
13211315
writableStream: writableStream,
13221316
info: info,
1323-
onClose: () {
1324-
cancelFun?.call();
1325-
},
1317+
onClose: cancelFun,
13261318
);
13271319

13281320
return byteWriter;

lib/src/preconnect/pre_connect_audio_buffer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class PreConnectAudioBuffer {
223223
Future<void> reset() async {
224224
await stopRecording();
225225
_timeoutTimer?.cancel();
226-
_participantStateListener?.call();
226+
await _participantStateListener?.call();
227227
_participantStateListener = null;
228228
_buffer.clear();
229229

lib/src/types/other.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'package:flutter/material.dart';
1919
import '../extensions.dart';
2020
import '../participant/participant.dart';
2121

22-
typedef CancelListenFunc = Function();
22+
typedef CancelListenFunc = Future<void> Function();
2323

2424
/// Protocol version to use when connecting to server.
2525
/// Usually it's not recommended to change this.

test/core/room_e2e_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void main() {
8787
await room.events.waitFor<ParticipantConnectedEvent>(duration: const Duration(seconds: 1));
8888

8989
// Clean up listener
90-
cancel();
90+
await cancel();
9191

9292
// Verify participant had tracks when connected event was emitted
9393
expect(participantHadTracksOnConnect, isTrue,

0 commit comments

Comments
 (0)