Call async function from Isolate function

2019-05-11 23:53发布

问题:

I am trying to call an async function from the Isolate function.

class IsolateExample {

  final ReceivePort port = new ReceivePort();

  IsolateExample(){
     Isolate.spawn(isolateFunction, port.sendPort);
  }

  static isolateFunction(SendPort port){
    print('inside isolateFunction');
    asyncFunction();
  }

  static void asyncFunction() async {
    print('inside asyncFunction');
  }
}

Usage of above class:

final IsolateExample _isolate = new IsolateExample();

Above code looks simple but asyncFunction never gets called. I do not have any clue why this is failing.

标签: dart flutter