iandis / isolated_worker

An isolated worker for Flutter (Isolate) and Web (Web Worker). Behaves almost the same as the compute function, except it is not a one-off worker.
MIT License
42 stars 11 forks source link

How to run hard process usig `JsIsolatedWorker` in web? #23

Open MacDeveloper1 opened 9 months ago

MacDeveloper1 commented 9 months ago

I need to execute some hard process in isolated worker in web. So below i my code

// some code above

void _onPrint() async {
  final worker = JsIsolatedWorker();
  final result = await _worker.run(functionName: 'tooSlowFunction', arguments: {}); // The result is expected
}

static Future<Uint8List> tooSlowFunction() async {
  print('I am here');
  return Uint8List(0);
}

// some code below

But I get an error

TypeError: t is not a function
worker.js 1:394  _d
worker.js 1:163  onmessage

What is wrong and how to get it work?