-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sharing code between isolates with FlutterIsolate.spawn #139
Comments
Off the top of my head, isn't it possible to send closures via SendPort? |
Let me rephrase the question briefly: Is it possible to use I haven't succeeded so far. I guess we agree that with If you're then assuming you're sending closures via |
In any case, anything non-primitive I've tried to send throws errors. So my main question still applies. Thanks. |
OK, after more tests I can edit my question. The reason why I would like to be able to use closures is because inside them I could put a message with non-primitive values and since I realize now that the reason why I can pass those non-primitive data is not for the Consequently, although So, the updated question is: is it possible to make In light of these tests I can say that I am complaining about the same problem indicated here. |
OK, I understand the issue more clearly now: objects/closures/SendPorts/etc can only be sent between isolates sharing the same code/process (e.g. Isolate.spawn). The isolates spawned by flutter_isolate do not share the same code, hence why you can't send these objects. There's no trivial fix for that. There might be some way to rejig the flutter_isolate package to do this (e.g. could we call Isolate.spawn, then attach a new Flutter engine to the spawned isolate?). I won't have time to look at that for quite some time though. |
Some possibly related info: flutter/flutter#94995 |
If I use Dart's
Isolate.run()
method I can send a closure as acomputation
parameter. If there are non-primitive variables in the closure, these are handled safely but I can't pass them in themessage
arguments.In the
flutter_isolate
package I don't have a similar functionality so I end up in this situation:flutter_isolate
I can only send references to top level and static methods, being able to use the native API plugins but I can't use closure;Isolate.run()
I can send closures (with data inside that I can't send in themessage
) but I can't use the native API plugins.Therefore, is it possible to have a
flutterRun()
function (similar toflutterCompile()
) or aFlutterIsolate.run
method (similar toFlutterIsolate.spawn
) which allows both to send closure (overcoming the problem of sending non-primitive variables) and at the same time be able to use the FlutterIsolate wrapper which allows me to use native API plugins?If it were possible, while waiting for this functionality, is it possible now to have a workaround to be able to send closures using the package wrapper?
Thank you.
The text was updated successfully, but these errors were encountered: