Skip to content

Commit 52b4942

Browse files
Document FIFO ordering guarantee (flutter#89441)
1 parent a14be9d commit 52b4942

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/flutter/lib/src/services/binding.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
6767
/// This is used to send messages from the application to the platform, and
6868
/// keeps track of which handlers have been registered on each channel so
6969
/// it may dispatch incoming messages to the registered handler.
70+
///
71+
/// The default implementation returns a [BinaryMessenger] that delivers the
72+
/// messages in the same order in which they are sent.
7073
BinaryMessenger get defaultBinaryMessenger => _defaultBinaryMessenger;
71-
late BinaryMessenger _defaultBinaryMessenger;
74+
late final BinaryMessenger _defaultBinaryMessenger;
7275

7376
/// The low level buffering and dispatch mechanism for messages sent by
7477
/// plugins on the engine side to their corresponding plugin code on
@@ -94,6 +97,11 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
9497

9598
/// Creates a default [BinaryMessenger] instance that can be used for sending
9699
/// platform messages.
100+
///
101+
/// Many Flutter framework components that communicate with the platform
102+
/// assume messages are received by the platform in the same order in which
103+
/// they are sent. When overriding this method, be sure the [BinaryMessenger]
104+
/// implementation guarantees FIFO delivery.
97105
@protected
98106
BinaryMessenger createBinaryMessenger() {
99107
return const _DefaultBinaryMessenger._();

packages/flutter/lib/src/services/platform_channel.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import 'message_codecs.dart';
2727
/// The logical identity of the channel is given by its name. Identically named
2828
/// channels will interfere with each other's communication.
2929
///
30+
/// All [BasicMessageChannel]s provided by the Flutter framework guarantee FIFO
31+
/// ordering. Applications can assume messages sent via a built-in
32+
/// [BasicMessageChannel] are delivered in the same order as they're sent.
33+
///
3034
/// See: <https://flutter.dev/platform-channels/>
3135
class BasicMessageChannel<T> {
3236
/// Creates a [BasicMessageChannel] with the specified [name], [codec] and [binaryMessenger].
@@ -95,6 +99,13 @@ class BasicMessageChannel<T> {
9599
/// The logical identity of the channel is given by its name. Identically named
96100
/// channels will interfere with each other's communication.
97101
///
102+
/// {@template flutter.services.method_channel.FIFO}
103+
/// All [MethodChannel]s provided by the Flutter framework guarantee FIFO
104+
/// ordering. Applications can assume method calls sent via a built-in
105+
/// [MethodChannel] are received by the platform plugins in the same order as
106+
/// they're sent.
107+
/// {@endtemplate}
108+
///
98109
/// See: <https://flutter.dev/platform-channels/>
99110
class MethodChannel {
100111
/// Creates a [MethodChannel] with the specified [name].
@@ -412,6 +423,8 @@ class MethodChannel {
412423
///
413424
/// When [invokeMethod] fails to find the platform plugin, it returns null
414425
/// instead of throwing an exception.
426+
///
427+
/// {@macro flutter.services.method_channel.FIFO}
415428
class OptionalMethodChannel extends MethodChannel {
416429
/// Creates a [MethodChannel] that ignores missing platform plugins.
417430
const OptionalMethodChannel(String name, [MethodCodec codec = const StandardMethodCodec(), BinaryMessenger? binaryMessenger])

0 commit comments

Comments
 (0)