1. @override
Future close()

Tells the stream sink that no further streams will be added.

This allows the stream sink to complete any remaining work and release resources that are no longer needed

Returns a future which is completed when the stream sink has shut down. If cleaning up can fail, the error may be reported in the returned future, otherwise it completes with null.

Returns the same future as done.

The stream sink may close before the close method is called, either due to an error or because it is itself providing events to someone who has stopped listening. In that case, the done future is completed first, and the close method will return the done future when called.

Unifies StreamConsumer.close and EventSink.close which both mark their object as not expecting any further events.

Source

@override
Future close() {
  _sendPort.send({"t": "stop"});
  return _stopCompleter.future.then((_) {
    if (isMaster) {
      receiver.close();
    } else {
      return new Future.delayed(new Duration(seconds: 1), () {
        receiver.close();
      });
    }
  });
}