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
This problem has been significantly improved, but still hits some very likely code patterns.
Example:
import"dart:isolate";
voidmain() {
var r =RawReceivePort();
r.handler = (v) {
print(v);
r.close();
};
var p = r.sendPort;
Isolate.run(() => p.send(42));
}
The closure only references p, a variable containing a SendPort, which should be sendable to any other isolate.
When running, you get the errror:
Invalid argument(s): Illegal argument in isolate message: (object is a ReceivePort)
#0 Isolate._spawnFunction (dart:isolate-patch/isolate_patch.dart:399:25)
...
which shows that the closure remembers the r variable, for no apparent reason. There is no reference to r in the function expression, or any time later. I'm assuming the earlier handler closure is what triggers the problem.
If I remove the r.close from the handler, the error goes away (but I also don't get to close the port).
This is a very likely problem, my first attempt to write an example of using Isolate.run to send multiple results was code precisely like this, and I had to introduce a helper function to work around it:
This problem has been significantly improved, but still hits some very likely code patterns.
Example:
The closure only references
p
, a variable containing aSendPort
, which should be sendable to any other isolate.When running, you get the errror:
which shows that the closure remembers the
r
variable, for no apparent reason. There is no reference tor
in the function expression, or any time later. I'm assuming the earlierhandler
closure is what triggers the problem.If I remove the
r.close
from the handler, the error goes away (but I also don't get to close the port).This is a very likely problem, my first attempt to write an example of using
Isolate.run
to send multiple results was code precisely like this, and I had to introduce a helper function to work around it:which moves the closure out of the scope of the
RawReceivePort
declaration.The text was updated successfully, but these errors were encountered: