6

I'm currently working with isolates to send queries in parallel to a database server. I have a connector-object to build the connection to the database and I would like to share that across all isolates, so I don't have to create a separate connection for every isolate.

So far it seems that I can only share special serializable objects between isolates. I'm using the send- and receive-ports for messaging. For other objects (such as my connector-object) the dart-vm yields the error:

Illegal argument(s): Illegal argument in isolate message : (object extends NativeWrapper)

Do you know of any way to share a generic object-instance between multiple isolates? Or do I have to create a separate instance for each isolate?

Thanks!

Pedro

4

1 回答 1

4

来自 SendPort.send 方法代码文档

   * In the special circumstances when two isolates share the same code and are
   * running in the same process (e.g. isolates created via [Isolate.spawn]), it
   * is also possible to send object instances (which would be copied in the
   * process). This is currently only supported by the dartvm.  For now, the
   * dart2js compiler only supports the restricted messages described above.

我假设也不支持作为本机对象包装器的对象。
目前似乎唯一的方法是在每个隔离中创建一个新连接。

这些价值观一直在起作用

   * The content of [message] can be: primitive values (null, num, bool, double,
   * String), instances of [SendPort], and lists and maps whose elements are any
   * of these. List and maps are also allowed to be cyclic.
于 2014-08-22T18:20:23.937 回答