blob: 9f471b6f5e201d2075a8da8a3c5114d6ee1166d3 [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/**
* @assertion Stream<E> asyncExpand<E>(Stream<E> convert(T event))
* Transforms each element into a sequence of asynchronous events.
*
* Returns a new stream and for each event of this stream, do the following:
* . . .
* - If the call returns null, no further action is taken for the elements.
*
* @description Checks that if convert returns null, no value is put on the
* output stream, just as if it returned an empty stream.
* @author ngl@unipro.ru
*/
import "dart:async";
import "dart:io";
import "../http_utils.dart";
import "../../../Utils/expect.dart";
var localhost = InternetAddress.loopbackIPv4;
main() async {
RawDatagramSocket producer = await RawDatagramSocket.bind(localhost, 0);
RawDatagramSocket receiver = await RawDatagramSocket.bind(localhost, 0);
List<List<int>> toSend = [[0, 1, 2, 3], [1, 2, 3], [2, 3], [3]];
bool wasSent =
await sendDatagram(producer, toSend, localhost, receiver.port);
Expect.isTrue(wasSent, "No datagram was sent");
Stream stream = receiver.asyncExpand((e) => null);
stream.length.then((value) {
Expect.equals(0, value);
});
receiver.close();
}