createGruntChannel function

Future<DuplexChannel> createGruntChannel(
  1. GruntFactory<Grunt> factory, {
  2. required bool isProduction,
})

Implementation

Future<DuplexChannel> createGruntChannel(GruntFactory factory,
    {required bool isProduction}) async {
  var _inbound = StreamController.broadcast();
  var port = RawReceivePort(_inbound.add);

  /// First thing is the isolate should return a proper sendPort.  We don't
  /// await this now because it won't actually be sent until after the Isolate
  /// is created.
  var sp = _inbound.stream.first.timeout(const Duration(seconds: 10));
  var isolate = await Isolate.spawn(_initializeGrunt, port.sendPort);
  final gruntPort = await sp as SendPort;
  gruntPort.send(factory.create);
  var dup = IsolateDuplexChannel(() => _inbound.stream, gruntPort, isolate);
  return dup;
}