有什么例子dart的`spawnUri(...)`在库“dart:isolate”? [英] Is there any example for dart's `spawnUri(...)` in library "dart:isolate"?

查看:227
本文介绍了有什么例子dart的`spawnUri(...)`在库“dart:isolate”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dart:isolate 中有一个 spawnUri(uri)函数,但我没有找到任何示例。



假设有两个文件,在第一个文件中,它会调用 spawnUri








b
$ b

  importdart:isolate; 

main(){
ReceivePort port = new ReceivePort();
port.receive((msg,_){
print(msg);
port.close();
});
var c = spawnUri(./ second.dart);
c.send([Freewind,enjoy dart],port.toSendPort());
}

second.dart
$ b

  String hello(String who,String message){
returnHello,$ who,$ message;
}

void isolateMain(ReceivePort port){
port.receive((msg,reply)=> reply.send(hello(msg [0],msg [1] ]));
}

main(){}

解决方案

strong>警告:此代码已过期。



请使用以下内容替换 second.dart

  importdart:isolate; 

String hello who,String message){
returnHello,$ who,$ message;
}

main(){
port.receive )=> reply.send(你好(MSG [0],味精[1])));
}


There is a spawnUri(uri) function in dart:isolate, but I don't find any example. I have guessed its usage, but failed.

Suppose there are 2 files, in the first one, it will call spawnUri for the 2nd one, and communicate with it.

first.dart

import "dart:isolate";

main() {
  ReceivePort port = new ReceivePort();
  port.receive((msg, _) {
    print(msg);
    port.close();
  });
   var c = spawnUri("./second.dart");
   c.send(["Freewind", "enjoy dart"], port.toSendPort());
}

second.dart

String hello(String who, String message) {
   return "Hello, $who, $message";
}

void isolateMain(ReceivePort port) {
  port.receive((msg, reply) => reply.send(hello(msg[0], msg[1]));
}

main() {}

But this example doesn't work. I don't know what's the correct code, how to fix it?

解决方案

WARNING : This code is out of date.

Replace your second.dart with the following to make it work :

import "dart:isolate";

String hello(String who, String message) {
  return "Hello, $who, $message";
}

main() {
  port.receive((msg, reply) => reply.send(hello(msg[0], msg[1])));
}

这篇关于有什么例子dart的`spawnUri(...)`在库“dart:isolate”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆