Closed sabin26 closed 10 months ago
Hello,
I've pushed changes to support your use-case.
Plase note that this will probably not work on Web (I haven't tested, but I guess functions cannot cross Web Worker boundaries. Even if they could, you'd have to implement a marshaler so that your T
instances can cross the border too. The overhead might negate the advantage of parsing and hydrating in a separate Web Worker).
Please also note that it may also not work on all platforms -- it's a bit difficult to tell exactly what is sendable across 2 isolates. Some info is available from Dart's doc on isolates as well as the doc for send().
Publishing the update now!
Regards
The doc for send() also mentions bug http://dartbug.com/36983 / https://github.com/dart-lang/sdk/issues/36983. This means if you provide a closure to the worker, it may end up capturing too many things. If this happens, maybe it can be worked around by passing a top-level function, or a static method / constructor tear-off (which is probably always preferable, anyways).
Hey, I am trying to parse JSON string to dart object using
Model.fromJson
method inside a squadron worker.This should work fine for a given model class (not tested though).
But what I want to do is parse the JSON string to a generic dart object with something as:
Here, I can't pass
fromJson
method as an argument. It doesn't let the build runner pass withsquadron_builder
. Previously when I was usingdart:isolate
, I was able to pass this usingSendPort
.My use-case is more complicated than this, but I am stuck by this issue. One way to solve this is by returning the
Map<String, Object?>
and usefromJson
from main thread. However, since I am offloading my task, I wanted to parse the Json to dart object from the worker thread.