drain method

Future<void> drain(
  1. String name,
  2. DrainChannelCallback callback

Remove and process all stored messages for a given channel.

This should be called once a channel is prepared to handle messages (i.e. when a message handler is set up in the framework).

The messages are processed by calling the given callback. Each message is processed in its own microtask.


// TODO(ianh): deprecate once framework uses [setListener].
Future<void> drain(String name, DrainChannelCallback callback) async {
  final _Channel? channel = _channels[name];
  while (channel != null && !channel._queue.isEmpty) {
    final _StoredMessage message = channel.pop();
    await callback(message.data, message.invoke);