Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 041f8e0

Browse files
committed
apply review comments
1 parent 91a9c64 commit 041f8e0

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

lib/ui/hooks.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ void _invoke(void callback()?, Zone zone) {
254254
}
255255

256256
/// Invokes [callback] inside the given [zone] passing it [arg].
257+
///
258+
/// The 1 in the name refers to the number of arguments expected by the callback.
257259
void _invoke1<A>(void callback(A a)?, Zone zone, A arg) {
258260
if (callback == null)
259261
return;
@@ -268,6 +270,8 @@ void _invoke1<A>(void callback(A a)?, Zone zone, A arg) {
268270
}
269271

270272
/// Invokes [callback] inside the given [zone] passing it [arg1] and [arg2].
273+
///
274+
/// The 2 in the name refers to the number of arguments expected by the callback.
271275
void _invoke2<A1, A2>(void callback(A1 a1, A2 a2)?, Zone zone, A1 arg1, A2 arg2) {
272276
if (callback == null)
273277
return;
@@ -284,6 +288,8 @@ void _invoke2<A1, A2>(void callback(A1 a1, A2 a2)?, Zone zone, A1 arg1, A2 arg2)
284288
}
285289

286290
/// Invokes [callback] inside the given [zone] passing it [arg1], [arg2], and [arg3].
291+
///
292+
/// The 3 in the name refers to the number of arguments expected by the callback.
287293
void _invoke3<A1, A2, A3>(void callback(A1 a1, A2 a2, A3 a3)?, Zone zone, A1 arg1, A2 arg2, A3 arg3) {
288294
if (callback == null)
289295
return;

testing/dart/channel_buffers_test.dart

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void main() {
3636
});
3737
});
3838

39-
test('deprecated drain is sync', () async {
39+
test('drain is sync', () async {
4040
const String channel = 'foo';
4141
final ByteData data = _makeByteData('message');
4242
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
@@ -78,7 +78,7 @@ void main() {
7878
expect(didCall, equals(false));
7979
});
8080

81-
test('empty', () async {
81+
test('drain when empty', () async {
8282
const String channel = 'foo';
8383
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
8484
bool didCall = false;
@@ -240,4 +240,51 @@ void main() {
240240
'-9',
241241
]);
242242
});
243+
244+
test('ChannelBuffers.clearListener', () async {
245+
final List<String> log = <String>[];
246+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
247+
final ByteData one = _makeByteData('one');
248+
final ByteData two = _makeByteData('two');
249+
final ByteData three = _makeByteData('three');
250+
final ByteData four = _makeByteData('four');
251+
buffers.handleMessage(_makeByteData('resize\ra\r10'));
252+
buffers.push('a', one, (ByteData data) { });
253+
buffers.push('a', two, (ByteData data) { });
254+
buffers.push('a', three, (ByteData data) { });
255+
log.add('-1');
256+
buffers.setListener('a', (ByteData data, ui.PlatformMessageResponseCallback callback) {
257+
log.add('a1: ${utf8.decode(data.buffer.asUint8List())}');
258+
});
259+
await null; // handles one
260+
log.add('-2');
261+
buffers.clearListener('a');
262+
await null;
263+
log.add('-3');
264+
buffers.setListener('a', (ByteData data, ui.PlatformMessageResponseCallback callback) {
265+
log.add('a2: ${utf8.decode(data.buffer.asUint8List())}');
266+
});
267+
log.add('-4');
268+
await null;
269+
buffers.push('a', four, (ByteData data) { });
270+
log.add('-5');
271+
await null;
272+
log.add('-6');
273+
await null;
274+
log.add('-7');
275+
await null;
276+
expect(log, <String>[
277+
'-1',
278+
'a1: one',
279+
'-2',
280+
'-3',
281+
'-4',
282+
'a2: two',
283+
'-5',
284+
'a2: three',
285+
'-6',
286+
'a2: four',
287+
'-7',
288+
]);
289+
});
243290
}

0 commit comments

Comments
 (0)