d-markey / squadron

Multithreading and worker thread pool for Dart / Flutter, to offload CPU-bound and heavy I/O tasks to Isolate or Web Worker threads.
https://pub.dev/packages/squadron
MIT License
79 stars 0 forks source link

Error: The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'List<dynamic>?' #19

Closed techouse closed 1 year ago

techouse commented 1 year ago

Hey 👋

I'm using squadron 5.0.0 with squadron_builder 2.1.2 and get this error when compiling my app.

lib/src/core/api/data/service/json_service.vm.g.dart:11:58: Error: The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'List<dynamic>?'.
 - 'Map' is from 'dart:core'.
 - 'List' is from 'dart:core'.
void _start(Map command) => run($JsonServiceInitializer, command, null);
                                                         ^
Target kernel_snapshot failed: Exception
techouse commented 1 year ago

I saw now that you have to configure it in build.yaml.

d-markey commented 1 year ago

Yep, just hoping that List is lighter/easier to transfer across Isolates and Web workers...

BTW thanks for providing an example integrating Squadron with Chopper. I see the example uses Squadron to deserialize the response from the REST API. I was wondering if you've tried to wrap the whole Chopper client inside a Squadron worker? So that the whole REST call is handled off the main thread, i.e. request serialization / API call / response deserialization.

techouse commented 1 year ago

I was essentially trying to replicate what the Flutter docs suggest:

If you run the fetchPhotos() function on a slower device, you might notice the app freezes for a brief moment as it parses and converts the JSON. This is jank, and you want to get rid of it.

You can remove the jank by moving the parsing and conversion to a background isolate using the compute() function provided by Flutter. The compute() function runs expensive functions in a background isolate and returns the result. In this case, run the parsePhotos() function in the background.

I haven't tried putting the whole REST call into a Worker. I'm not sure what the benefit of that would be and it could get quite tricky when passing JWT tokens around, however, I'll take a look at it once I got a bit more free time :)

d-markey commented 1 year ago

Don't bother, I was just being curious :-)