receive method
Reads one value from the channel. Returns immediately if a value is available in the channel. If the channel is empty, a future is returned that resolves with the value when a new value is available.
Implementation
@override
Future<ChannelEvent<T>> receive() async {
if (_isClosed && _data.isEmpty) {
return ChannelEvent<T>(null, true);
}
if (_data.isNotEmpty && _completers.isEmpty) {
return ChannelEvent<T>(_data.removeFirst(), false);
}
final completer = Completer<ChannelEvent<T>>();
_completers.add(completer);
return completer.future;
}