lamnhan066/isolate_manager

A generator to generate the Worker `js` automatically based on the `@IsolateManagerWorker()` anotation

Closed this issue · 2 comments

To Do

  • [Not Planned] A generator runs along with the build_runner command.
  • A generator run by dart run isolate_manager:generate command.

Concept:

This is a function to add 2 integers:

@IsolateManagerWorker('add')
int add(List<int> params) {
  return params[0] + params[1]
}

The parameter add is optional, the name of the function will be used if it's not specified. To create the js inside a subfolder like workers, change the name add to workers/add.

After running the above command, a temp file will be created with the current file's contents. An import will be added at the beginning and a main will be created at the end of the script like this:

import 'package:isolate_manager/isolate_manager.dart';

//  Other codes...

main() {
  IsolateManagerFunction.workerFunction(add);
}

Then run the dart compile js "path/to/tempFile.dart" -o "web/add.js" -O4 command.

Removes the temp File.

Completed.

Instead of adding an import and a main function to the current file, we only need to create a new file and import the current file. For instance:

import 'functions.dart';
import 'package:isolate_manager/isolate_manager.dart';

main() {
  IsolateManagerFunction.workerFunction(add);
}

This issue will be closed because the command generator has been implemented, and there are no plans for the build runner.