rmawatson / flutter_isolate

Launch an isolate that can use flutter plugins.
MIT License
269 stars 80 forks source link

Illegal argument in isolate message : (object is a regular Dart Instance) #134

Closed Dev11-ultroNeous closed 1 year ago

Dev11-ultroNeous commented 1 year ago

Hi I use this package for calling multiple Api simultaneously on the background to facing this issue I have one repo here it is https://github.com/Dev11-ultroNeous/workers

Kindly check it and suggest a solution. Thank you!

nmfisher commented 1 year ago

1) Can you be a bit more specific - which file/line are you having trouble with? 2) What version of flutter are you running?

Dev11-ultroNeous commented 1 year ago

Hello @nmfisher This is the file link: https://github.com/Dev11-ultroNeous/workers/blob/5ab81b4ddd42fb6dec084024aa2c2a91a5e287c7/lib/worker_manager/src/worker/worker_io.dart#L39

flutter version:

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.10, on macOS 13.2.1 22D68 darwin-arm, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.76.0) [✓] Connected device (2 available) [✓] HTTP Host Availability

• No issues found!

nmfisher commented 1 year ago

I ran the project and didn't get an exception at the exact line you specified, but did get another similar exception which indicates you're trying to send an object containing a Function through a SendPort.

You should review the docs here:

https://api.dart.dev/stable/2.19.3/dart-isolate/SendPort/send.html

and ensure you are only trying to send compatible objects. If you need to send a Function (presumably some type of callback), you will need to restructure your project (e.g. you can replace the callback with another SendPort and then call the callback in your main isolate).

Dev11-ultroNeous commented 1 year ago

Hello @nmfisher can I use this package to call multiple APIs simultaneously with pause and resume functionality?

nmfisher commented 1 year ago

That's an incredibly vague question which is too difficult to answer. There's no inherent reason why you can't use flutter_isolate to make multiple HTTP requests in the background, but you still need to correctly use spawn/SendPort/ReceivePort, though.

It sounds like you need to think through your application structure carefully to figure out what needs to run on the main isolate, what needs to be run on the background isolate(s), and how to pass messages between the two.

Dev11-ultroNeous commented 1 year ago

Hello @nmfisher,

Here once I have mentioned the requirement and the error that I am facing during the flow.

Aim:

Issue:

nmfisher commented 1 year ago

Can you please try to describe your issues more clearly, you've given three different descriptions of your problem and you've now opened another issue which seems to duplicate the issue you describe in your last comment in this thread.

I'll assume that everything falls under your new issue so I will close this for now.