Open abbashosseinii opened 4 days ago
Hi @abbashosseinii
Can you let me know the way that you send and receive a Map via Worker? I think we have no similar Dart Map in JS so we cannot send a Map directly to the JS. The only way I can do is by using jsonEncode
and jsonDecode
.
Hello dear @lamnhan066
This is possible. We just need our models to work with Map<dynamic, dynamic>
in the toJson
and fromJson
methods. I wrote a simple project where I implemented this using a basic worker.js
. I’ll attach the project link below. Thank you for your quick response.
Sample project
Hi @abbashosseinii
If you are using the toJson
and fromJson
the the package will work flawlessly when you're using String like this (I copied this from the document) :
main() async {
final isolate = IsolateManager.create(
aStringIntMap,
workerName: 'aStringIntMap',
isDebug: true,
);
await isolate.start();
final map = {'a': 1, 'b': 2, 'c': 3};
final result = await isolate.compute(jsonEncode(map));
expect(jsonDecode(result), map);
}
@isolateManagerWorker
String aStringIntMap(String params) {
return params;
}
Dear @lamnhan066
I opened this issue for three reasons:
The solution you provided for encoding and decoding is not compatible with the web platform, and the main reason I chose this package over conventional methods is to leverage multi-threading in the web environment.
In cases where large amounts of data need to be transferred, like in the project I’m currently working on, this encoding and decoding process becomes a very time-consuming operation.
We can only solve this issue if we remove the current limitations on input and output and handle it through Map, as I explained earlier. This way, we can significantly reduce the computational load and noticeably shorten task completion times.
Hi @abbashosseinii
I misunderstood your last opinion because at first, I thought your toJson
returns a String
instead of a Map
. I just realized that when I looked into the worker.js
. I think the issue was caused when compiling from Dart to JS (your script was written in JS native).
I think I will try to write a simple script in Dart using a Map
, compile it to JS and let’s see if I can find any way to make it work.
Thank you for your information.
@lamnhan066 Thank you so much! Wish you success!
Hello,
I encountered an issue while using the isolate-manager package. It seems that I’m unable to pass a Map as an input or output when using isolate-manager, which leads to problems when handling large data transfers.
As a workaround, I was able to send and receive a Map using a worker without any issues. However, when attempting the same process using isolate-manager, the error occurs, and the UI freezes during jsonEncode and jsonDecode.
Is there any way to resolve this issue or support passing a Map?
Thank you for your assistance!
Steps to Reproduce:
Expected Behavior:
Be able to pass a Map without encountering an error.
Environment: