mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Revert "Make drain() consistently asynchronous. (#21062)" (flutter/engine#21391)
This reverts commit 7a237c9b68fc5fc2813c732d316e9cde5a932def.
This commit is contained in:
parent
e290dd1984
commit
49b2401dfe
@ -181,11 +181,7 @@ class ChannelBuffers {
|
||||
///
|
||||
/// This should be called once a channel is prepared to handle messages
|
||||
/// (i.e. when a message handler is setup in the framework).
|
||||
///
|
||||
/// The messages are processed by calling the given `callback`. Each message
|
||||
/// is processed in its own microtask.
|
||||
Future<void> drain(String channel, DrainChannelCallback callback) async {
|
||||
await null; // Ensures that the rest of this method is scheduled in a microtask.
|
||||
while (!_isEmpty(channel)) {
|
||||
final _StoredMessage message = _pop(channel)!;
|
||||
await callback(message.data, message.callback);
|
||||
|
||||
@ -119,7 +119,6 @@ class ChannelBuffers {
|
||||
}
|
||||
|
||||
Future<void> drain(String channel, DrainChannelCallback callback) async {
|
||||
await null; // Ensures that the rest of this method is scheduled in a microtask.
|
||||
while (!_isEmpty(channel)) {
|
||||
final _StoredMessage message = _pop(channel)!;
|
||||
await callback(message.data, message.callback);
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
@ -36,32 +34,6 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('drain is async', () async {
|
||||
const String channel = 'foo';
|
||||
final ByteData data = _makeByteData('message');
|
||||
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
|
||||
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
|
||||
buffers.push(channel, data, callback);
|
||||
final List<String> log = <String>[];
|
||||
final Completer<void> completer = Completer<void>();
|
||||
scheduleMicrotask(() { log.add('before drain, microtask'); });
|
||||
log.add('before drain');
|
||||
buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
|
||||
log.add('callback');
|
||||
completer.complete();
|
||||
});
|
||||
log.add('after drain, before await');
|
||||
await completer.future;
|
||||
log.add('after await');
|
||||
expect(log, <String>[
|
||||
'before drain',
|
||||
'after drain, before await',
|
||||
'before drain, microtask',
|
||||
'callback',
|
||||
'after await'
|
||||
]);
|
||||
});
|
||||
|
||||
test('push drain zero', () async {
|
||||
const String channel = 'foo';
|
||||
final ByteData data = _makeByteData('bar');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user