Closed abdelaziz-mahdy closed 10 months ago
Hello,
you're right, not all Dart classes can be transfered to Web workers. Base types (lists, ints, strings...) will happily cross Web worker boundaries, but custom types will not.
To work around this issue, you should implement your own serializers (marshalers in Squadron, see class SquadronMarshaler
). You will find examples here: https://github.com/d-markey/squadron_sample/tree/main/lib/src/json/marshalers. These serializers should make sure only base types are used.
Just to be sure the builder does not automatically generate those classes? And is there an annotations to make it auto generated by builder?
Or do I have to implement each class marshalers by myself
Nope, serialization is up to you and can be a sensitive topic for performance.
Depending on the "shape" of your data, you might want to serialize using a binary buffer eg Int32List
or to string eg Json. If your data contains other classes / list of objects, the nested level and/or the list length can impact perf depending on the serialization strategy. squadron_builder cannot make that choice.
You mighty be interested in https://github.com/d-markey/squadron_builder/issues/9 for performance aspects on VM vs Web.
Nope, serialization is up to you and can be a sensitive topic for performance.
Depending on the "shape" of your data, you might want to serialize using a binary buffer eg
Int32List
or to string eg Json. If your data contains other classes / list of objects, the nested level and/or the list length can impact perf depending on the serialization strategy. squadron_builder cannot make that choice.You mighty be interested in https://github.com/d-markey/squadron_builder/issues/9 for performance aspects on VM vs Web.
Thank you for mentioning the issue, this is the issue I checked before, when I got stuck,
I think I will go with converting the parameters to map and using that map in the function
If possible for the sake of future devs using the builder can a warning be added for this problem if they are not using basic types?
Could be helpful indeed, I'll keep that in mind for a future release. Closing this issue as resolved, don't hesitate to open another one or reopen this one if you need more help!
Thank you very much for your help, and I will see if I could implement a pr
Hello,
Firstly, I want to express my gratitude for the awesome squadron package and its builder. It's been incredibly useful in my project. However, I've encountered an issue when running my Flutter web app. I'm getting an UnimplementedError: structured clone of other type. This error doesn't occur on macOS, but it appears on the web.
From my research, it seems the problem is related to using classes that are not serializable by JavaScript. Could you provide guidance on how to make these classes serializable for the web? I read something about marshallers in the issues section; can they be used to resolve this issue?
For reference, here's the link to the code: bouncy_ball_physics on GitHub.
Thank you for your help and the fantastic work on this package!