【发布时间】:2017-03-22 10:14:54
【问题描述】:
我在使用 Dart 中的隔离时遇到了一些困难。第一个问题是我想使用 dart:js 在我的一个隔离中使用 javascript 库。我尝试使用以下代码:
void runCode(SendPort sendPort)
{
print("still ok...");
JsObject object = new JsObject(context['jsCode']);
print("still ok?");
}
void main()
{
ReceivePort receivePort = new ReceivePort();
JsObject object = new JsObject(context['jsCode']);
print("ok so far");
Isolate.spawn(runCode, receivePort.sendPort);
}
代码在 runCode 函数中运行到“还可以...”,当我尝试使用 JsObject 时会中断。
第二个问题是我想在隔离中使用文件系统 API。所以我尝试了以下方法:
void runCode(SendPort sendPort)
{
window.requestFileSystem.then((FileSystem filesytem) => print('ok'));
}
void main()
{
ReceivePort receivePort = new ReceivePort();
Isolate.spawn(runCode, receivePort.sendPort);
}
当我到达文件系统时,第二个示例中断。
我已阅读:Dart : Isolate not working when using html import 并且从这里它表明 dart:html 不能在隔离中使用。这是文件系统 API 不起作用的原因吗? dart:js 也是这样吗?还是我完全错过了什么?
感谢您的帮助!
【问题讨论】:
-
AFAIK 当不再依赖 Dartium 进行开发时,这将通过 DDC(Dart 开发编译器)修复,这使得此类场景变得复杂。
标签: dart dart-js-interop dart-isolates