【问题标题】:Dart isolate call or sendDart 隔离调用或发送
【发布时间】:2013-07-24 13:32:02
【问题描述】:

我有几个关于隔离如何工作的问题:

1) callsend 有什么区别,什么时候应该使用 call 而不是 send

2) 只是好奇,有没有办法像我们链接Future 一样链接隔离?

3)

import 'dart:isolate';
echo() {
  port.receive((msg, reply) {
    print('I received: $msg');
  });
}

main() {
  var sendPort = spawnFunction(echo);
  sendPort.call('Hello from main');
}

它显示:我收到:来自 main 的 Hello

但是当我使用send 时,它什么也没打印,为什么?

【问题讨论】:

    标签: dart dart-isolates


    【解决方案1】:

    使用SendPort 上的call() 方法作为发送消息和接收回复的简单方法。 call() 方法返回一个 Future 用于回复。如果您不介意回复而只想发送消息,请使用send()

    查看dart:isolate - Concurrency with Isolates了解更多信息。

    对于 3) 它在上面的链接中进行了解释:

    在独立 VM 中,main() 函数在第一个隔离(也称为 根隔离)中运行。当根隔离终止时,它会终止整个 VM,而不管其他隔离是否仍在运行。如需更多信息,请参阅the section called “Keeping the root isolate alive”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多