dart-archive / isolate

Makes working with Dart isolates easier.
https://pub.dev/packages/isolate
BSD 3-Clause "New" or "Revised" License
90 stars 34 forks source link

Unhandled Exception: Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '<anonymous closure>':.) #56

Closed youngchan1988 closed 3 years ago

youngchan1988 commented 3 years ago

The exception throw by the code:

  @override
  Future<R> run<R, P>(FutureOr<R>? Function(P argument) function, P argument,
      {Duration? timeout, FutureOr<R> Function()? onTimeout}) {
    return singleResultFuture<R>((SendPort port) {
      _commandPort.send(list4(_run, function, argument, port));
    }, timeout: timeout, onTimeout: onTimeout);
  }

in isolate_runner.dart. What I am curious about is the SendPort can only transfer primitive values. https://api.dart.dev/stable/2.13.0/dart-isolate/SendPort/send.html

The content of message can be: primitive values (null, num, bool, double, String), instances of SendPort, and lists and maps whose elements are any of these. List and maps are also allowed to contain cyclic references.

So why send the function type argument?