generateWorkerIsolateScript function

String generateWorkerIsolateScript(
  1. List<InputFile> inputFiles
)

Implementation

String generateWorkerIsolateScript(List<InputFile> inputFiles) =>
    CodeTemplate(children: [
      ...inputFiles
          .map((file) => DartImport(fullClassName: file.relativePath))
          .toList(),
      DartImport(fullClassName: 'dart:io'),
      DartImport(fullClassName: 'dart:isolate'),
      DartImport(fullClassName: 'package:unify/worker/worker.dart'),
      EmptyLine(),
      DartFunction(
        functionName: 'main',
        isAsync: true,
        params: [
          Variable(AstList(generics: [AstString()]), 'args'),
          Variable(AstCustomType('SendPort'), 'sendPort')
        ],
        body: (depth) {
          final funcEncode = <CodeUnit>[];
          funcEncode.add(OneLine(
              depth: depth + 1,
              body: 'sendPort.send(await isolateRun(args));'));
          return funcEncode;
        },
      )
    ]).build();