没有声明顶层方法'spawnFunction' [英] No top-level method 'spawnFunction' declared
问题描述
我想在Dart中使用Isolates。 dartlang.org的教程似乎使用函数 spawnFunction
。但这似乎并不适用于我。我不能找到关于这个的任何文档。
I'm trying to use Isolates in Dart. The tutorials from dartlang.org seem to use the function spawnFunction
. But that does not seem to work for me. And I cant find any docs about this.
import 'dart:isolate';
void doThing() {
print('Hello!');
}
main() {
spawnFunction(doThing);
}
。
Unhandled exception:
No top-level method 'spawnFunction' declared.
来自 api.dartlang.org Isolate.spawn
但我得到一个错误,说没有静态方法 spawn
声明。
The docs from api.dartlang.org mention Isolate.spawn
but I get an error saying there is no static method spawn
declared.
我错过了什么吗?
谢谢!
推荐答案
Isolate.spawn确实是创建隔离的新方法。您的示例需要重写为:
Isolate.spawn is indeed the new way of creating isolates. Your example would need to be rewritten as:
import 'dart:isolate';
void doThing(_) {
print("Hello!");
}
main() {
Isolate.spawn(doThing, null);
}
请参阅 https://groups.google.com/a/dartlang.org/forum/#!topic/misc/EVUMkZXFXtY 用于中断更改公告。
See https://groups.google.com/a/dartlang.org/forum/#!topic/misc/EVUMkZXFXtY for the breaking change announcement.
这篇关于没有声明顶层方法'spawnFunction'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!