You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #47972@lrhn said there was probably already an issue for this, but I couldn't find it, so apologies if this is a duplicate.
If closures only closed over variables that are actually used inside the closure, it would make working with Isolates easier.
As of dart 2.15 Isolate.spawn can accept a closure, but will fail at runtime if one of the variables it closes over is one of the non supported message types like a ReceivePort, or UserTag. The program will fail even if the variable is never used within the closure itself.
Consider this example program.
import'dart:isolate';
voidmain() async {
final receivePort =ReceivePort();
int three =3;
awaitIsolate.spawn(
(SendPort port) =>Isolate.exit(port, [1, 2, three]),
receivePort.sendPort,
);
print(receivePort.first);
}
Which fails at runtime with the error message:
Unhandled exception:
Invalid argument(s): Illegal argument in isolate message: (object is aReceivePort)
The text was updated successfully, but these errors were encountered:
In #47972 @lrhn said there was probably already an issue for this, but I couldn't find it, so apologies if this is a duplicate.
If closures only closed over variables that are actually used inside the closure, it would make working with
Isolate
s easier.As of dart 2.15
Isolate.spawn
can accept a closure, but will fail at runtime if one of the variables it closes over is one of the non supported message types like a ReceivePort, or UserTag. The program will fail even if the variable is never used within the closure itself.Consider this example program.
Which fails at runtime with the error message:
The text was updated successfully, but these errors were encountered: