1. override
Stream<ProxyDef> bind(Stream<ProxyDef> stream)

Transform the incoming stream's events.

Creates a new stream. When this stream is listened to, it will start listening on stream, and generate events on the new stream based on the events from stream.

Subscriptions on the returned stream should propagate pause state to the subscription on stream.

Source

@override
Stream<ProxyDef> bind(Stream<ProxyDef> stream) {
  var _stream = new StreamController<ProxyDef>();

  stream.toList().then((proxies) async {
    int i = -1;
    totalProxies = proxies.length;

    await Future.forEach(proxies, (ProxyDef proxy) async {
      if (i == totalProxies - 1)
        stdout.write("100% complete (proxy $totalProxies/$totalProxies)...");
      else stdout.write("\r${(++i * 100.0 / totalProxies).toStringAsFixed(2)}% complete (proxy ${i + 1}/$totalProxies)...");
      bool success = true;

      try {
        ProxyClient _client = new ProxyClient(proxy, timeout);

        // Check each URL
        for (String url in urlsToCheck) {
          var response = await _client.get(url);
          //print("Body: ${response.body}");
        }

        // Pokemon
        if (pokemon != null) {
          //var pkmn = new PokemonClient(_client, pokemon);
        }

        _client.close();
      } catch (_) {
        success = false;
      }

      if (success) {
        _stream.add(proxy);
      }
    });

    stdout.writeln("\r\nFinished checking $totalProxies proxy(ies).");
    _stream.close();
  });

  return _stream.stream;
}